[HOW] Import Undo

General TRichView support forum. Please post your questions here
Post Reply
Marsianin
Posts: 193
Joined: Sun Sep 25, 2005 11:03 pm

[HOW] Import Undo

Post by Marsianin »

Just tried to implement undo for OfficeConverters file import.
I want to import several .doc files and create undo point after each import but this seems not working:

Code: Select all

RichViewEdit1.TopLevelEditor.BeginUndoGroup(rvutInsert);
RichViewEdit1.TopLevelEditor.SetUndoGroupMode(True);
try
  r:=RVOfficeConverter1.ImportRV(OpenDialog1.FileName,RichViewEdit1,OpenDialog1.FilterIndex);
finally
  RichViewEdit1.TopLevelEditor.SetUndoGroupMode(False);
end;
After this code I'm getting .doc file imported and undo button enabled but pressing it does nothing just disabling :shock:

Also is there a way to import file from the cursor position?
Sergey Tkachenko
Site Admin
Posts: 17577
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

ImportRV uses RichViewEdit.LoadRTF inside that cannot be undone.

If you want to insert at the position of caret:

Code: Select all

r:=RVOfficeConverter1.ImportRTF(OpenDialog1.FileName, OpenDialog1.FilterIndex); 
if r then begin
  RVOfficeConverter1.Stream.Position := 0;
  RichViewEdit1.InsertRTFFromStream(RVOfficeConverter1.Stream);
end;
If you want to replace the existing content:

Code: Select all

r:=RVOfficeConverter1.ImportRTF(OpenDialog1.FileName, OpenDialog1.FilterIndex); 
if r then begin
  RVOfficeConverter1.Stream.Position := 0;
  RichViewEdit1.SelectAll;
  RichViewEdit1.InsertRTFFromStream(RVOfficeConverter1.Stream);
end;
If you want to add to the end:

Code: Select all

r:=RVOfficeConverter1.ImportRTF(OpenDialog1.FileName, OpenDialog1.FilterIndex); 
if r then begin
  RVOfficeConverter1.Stream.Position := 0;
  ItemNo := RichViewEdit1.ItemCount-1;
  RichViewEdit1.SetSelectionBounds(
    ItemNo, RichViewEdit1.GetOffsAfterItem(ItemNo),
    ItemNo, RichViewEdit1.GetOffsAfterItem(ItemNo));
  RichViewEdit1.InsertRTFFromStream(RVOfficeConverter1.Stream);
end;
Post Reply