problem move content with control to other position .

General TRichView support forum. Please post your questions here
Post Reply
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

problem move content with control to other position .

Post by chuqingsheng »

I have a table with some controls(button,image) in it, and those controls have onclick event code. when I cut the table and paste to other position(btw, in same richviewedit) by progam. I hope those controls onclick event work.

but the onclick event lost.

Code: Select all

//src_no is the table ItemNo.
//dst_no is the new position ItemNo that the table moved to


  _MainRVE.SetSelectionBounds(src_no, 0, src_no, 1);

  stream := TMemoryStream.Create;
  _MainRVE.SaveRVFToStream(stream, True);

  _MainRVE.DeleteParas(src_no, src_no); //delete the table

  _MainRVE.Reformat;
  dst_no := FindItemNoByItemName(dstId);  //find the destation ItemNo

  _MainRVE.SetSelectionBounds(dst_no, 0, dst_no, 0); //move caret

  stream.Position := 0;
  _MainRVE.InsertRVFFromStreamEd(stream);
  stream.Free;

  _MainRVE.Reformat;


another problem.

I have a image in richviewedit. in the image onclick event, change the image picture. but the richviewedit scroll up so image not in current vision and when scroll back ,the image's picture gone.

Code: Select all

//image onclick event code

    img := TImage(Sender);
    if img.Tag = 0 then
    begin

      img.Picture.Bitmap := nil;
      img.Picture.LoadFromFile(_AppResourceDir + 'RadioTrue.png');
      img.Tag := 1;
    end
    else
    begin
      img.Picture.Bitmap := nil;
      img.Picture.LoadFromFile(_AppResourceDir + 'RadioFalse.png');
      img.Tag := 0;
    end;

   _MainRVE.Reformat;

Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

1) Events are not stored in RVF files. You need to reassign them for all controls when a document is loaded. Use OnControlAction event for this.
Example: http://www.trichview.com/forums/viewtopic.php?t=157
Sergey Tkachenko
Site Admin
Posts: 17559
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

2) You cannot use Tags of controls inserted in TRichView. TRichView uses them itself (to make calculations related to their positions, what's why a control can disappear if you modify its tag).
You need to choose another way to store value.
For example, you can create a class inherited from TImage:

Code: Select all

type
  TCheckImage = class (TImage)
    private
      FChecked: Boolean;
    published
      property Checked: Boolean read FChecked write FChecked default False;
  end;
Now you can use Checked instead of Tag.
See also how to implement radio buttons without images at all:
http://www.trichview.com/forums/viewtopic.php?t=1327
chuqingsheng
Posts: 38
Joined: Sat Nov 06, 2010 5:12 am

Post by chuqingsheng »

Thank you very much.

yes , I have found the tag of control has changed after reformat.

Thank you again.
Post Reply