How can insert Hypertext in RichviewEdit

General TRichView support forum. Please post your questions here
Post Reply
comeonwh
Posts: 10
Joined: Tue Feb 21, 2006 4:09 am

How can insert Hypertext in RichviewEdit

Post by comeonwh »

Hello,

I am using the RichViewEdit to list the record contents , which read from database. These records increase at any moment, so the RichViewEdit reads all new records from database per second and paints record contents.My code as follows:

Code: Select all

Type
  TInfo = Record
    title:string;
    phone:string;
    name:string;
    content:string;
End;


function MakeTag(s: String): Integer;
begin
   Result := Integer(StrNew(PChar(s)));
end;


//Add record into RichViewEdit
procedure ListRecord;
var
   myInfo:TInfo;
   RichVE:TRichViewEdit;
   content_1,content_2:string;
begin
   content_1:=myInfo.content; //РЕПўДЪИЭТ»
   content_2:='name:='+ myInfo.name + ',' + myInfo.content; //РЕПўДЪИЭ¶ю   

   RichVE.AddNL(myInfo.title,0,2); //ФцјУ±кМв
   RichVE.AddTab(0,-1);
   RichVE.AddHotspotExTag('µз»°',1,1,ImageList,-1,MakeTag(myInfo.phone)); //ФЪ±кМвєуГжФцјУµз»°Нј±кі¬ј¶БґЅУЈ¬µг»чёГБґЅУ¶ЇМ¬ПФКѕµз»°єЕВл
   RichVE.AddNlTag(content_1,2,0,MakeTag(content_2));//РЕПўДЪИЭµДі¬ј¶БґЅУ,ХэіЈПФКѕКЗ content_1µДДЪИЭ,µ±УГ»§µг»чК±,ПФКѕ content_2 µДДЪИЭ.
   RichVE.AddBreakEx(0, rvbsLine, clRed);   //»­МхПЯ
   RichVE.FormatTail;
              
end;


//RichVE onJump Event
procedure RichVEJump(Sender: TObject; id: Integer);
var
   RVData: TCustomRVFormattedData;
   ItemNo: Integer;
   i:integer;
   hideInfo:string;
begin
   RichVE.GetJumpPointLocation(id,Rvdata,itemNo);
   
   if RVData<>nil then begin
      hideInfo := GetTagStr(RVData.GetItemTag(ItemNo));
      RichVE.ReadOnly := false;

      RichVE.SetItemTextEd(ItemNo,hideInfo);//¶ЇМ¬ЙиЦГПФКѕµДРЕПўОЄТюІШµДРЕПўДЪИЭ
      
      RichVE.ReadOnly := true;
      RichVE.Refresh;  
    
  end;

end;


as above code, it can append record into RichViewEdit ,list Hypertext contents,and can dynamic paints the contents when user clicked.
Now, I want to insert the ervery record into RichViewEdit at line 0,but not append the last line.

I have tested, used the "insert" method must be modify mode,but the Hypertext can not answer "onJump" events.

Q:
How can insert contents into RichViewEdit at line 0 and the hypertext can answer "onJump" events.

The cursor always at the last line or fist line,when insert record into RichViewEdit.
How can I locked a certain line,when insert record or append record,RichViewEdit not ScrollTo the last line .
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Fast addition in TRichView is possible only to the end of document, because in this case you can use FormatTail method to reformat only the affected part of document.
Even if you will be able to insert at the beginning, you will need to reformat the whole document by Format method. Time of reformatting is much more important than time of document creation, so it may be makes sense to rebuild document on scratch.

Or, if you use TRichViewEdit, you can insert at caret position using editing methods such as InsertText, InsertHotspot, etc. Caret can be moved to the beginning by rv.SetSelectionBounds(0, rv.GetOffsBeforeItem(0), 0, rv.GetOffsBeforeItem(0)). Calling Format or FormatTail is not needed for editing methods.

PS: there is a potential bug in your code, change
RichVE.SetItemTextEd(ItemNo,hideInfo);
to
RichVE.TopLevelEditor.SetItemTextEd(ItemNo,hideInfo);
comeonwh
Posts: 10
Joined: Tue Feb 21, 2006 4:09 am

Post by comeonwh »

Hello,
Thanks,Sergey Tkachenko.

If I use TRichViewEdit, how can I insert at caret position using editing methods such as InsertText, InsertHotspot, etc.

Can you give me demo code?
Or, I post a demo code to your E-mail,and you help me to change it.

It is very important which Insert Hypertext at the beginning, and can answer the "Onjump" event.

Thank you very much,Sergey Tkachenko.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Use SetSelectionBounds to move caret to the proper place, then call these Insert*** methods.

Note: in editor, OnJump occurs on a simple click only if ReadOnly property = True. Otherwise, you need to hold Ctrl key when clicking (and rvoCtrlJumps must be included in EditorOptions property).
comeonwh
Posts: 10
Joined: Tue Feb 21, 2006 4:09 am

Post by comeonwh »

Thanks,Sergey Tkachenko.

How can I uses insert*** methos to accomplish the code function as as follows:

Code: Select all

   RichVE.AddNL(myInfo.title,0,2); // add title.
   RichVE.AddTab(0,-1);   // add TAB key.
   RichVE.AddHotspotExTag('phone',1,1,ImageList,-1,MakeTag(myInfo.phone)); // add a hostpot image,on click show "myInfo.phone" content. above all on the first line.
  RichVE.AddNlTag(content_1,2,0,MakeTag(content_2));//add a hostpot text ,on click show content_2 info, this at second line. 
   RichVE.AddBreakEx(0, rvbsLine, clRed);   //add line at third line.

please give me the code,that uses insert*** methos.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

How to insert such fragment at the caret position?

This code assumes that content_1 does not have line break characters (#13 or #10):

Code: Select all

RichVE.TopLevelEditor.BeginUndoGroup(rvutInsert);
RichVE.TopLevelEditor.SetUndoGroupMode(True)
try
  RichVE.InsertText(#13);
  RichVE.ApplyParaStyle(2);
  RichVE.ApplyTextStyle(0);
  RichVE.InsertText(myInfo.title);
  RichVE.InsertTab;
  if RichVE.InsertHotspot(1,1,ImageList) then begin
    RichVE.SetCurrentItemText('phone');
    RichVE.SetCurrentTag(MakeTag(myInfo.phone));
  end;
  RichVE.InsertText(#13);
  RichVE.ApplyParaStyle(0);
  RichVE.ApplyTextStyle(2);
  RichVE.InsertStringTag(content_1, MakeTag(content_2));
  RichVE.InsertBreak(0, rvbsLine, clRed);   
finally
  RichVE.TopLevelEditor.SetUndoGroupMode(False);
end;
comeonwh
Posts: 10
Joined: Tue Feb 21, 2006 4:09 am

Post by comeonwh »

Sergey Tkachenko,thank you very much!
All problems be ravel out.
Post Reply