Saving SelStart, SelLen and scroll positions

General TRichView support forum. Please post your questions here
Post Reply
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Saving SelStart, SelLen and scroll positions

Post by standay »

Sergey,

I am saving my RVF SelStart, SelLen and scroll positions in the file itself. I prefer that to using an external INI or XML file. Here's what I'm using:

Code: Select all

    rve.SetItemExtraStrProperty(0, rvespTag,
      SelStart.ToString + ',' + SelLen.ToString + ',' +
        VScroll.ToString + ',' + HScroll.ToString ) ;
    rve.SaveRVF( EntryPath + FileName, false );
When I read it back, I use this:

Code: Select all

    SelStart := 0;
    SelLen := 0;
    VScroll := 0;
    HScroll := 0;
    tempList:= TStringList.Create;
    rve.GetItemExtraStrProperty(0, rvespTag, temp );
    tempList.DelimitedText := temp;
    if tempList.Count = 4 then
    begin
      SelStart := StrToInt(tempList.Strings[0]);
      SelLen := StrToInt(tempList.Strings[1]);
      VScroll := StrToInt(tempList.Strings[2]);
      HScroll := StrToInt(tempList.Strings[3]);
    end;
    
This is actually working pretty well, and I'll do some additional error trapping later. But my questions now are:
  • Is there a built-in function somewhere that will do this that I've missed?
  • If not, is using GetItemExtraStrProperty(0, rvespTag, temp ) OK?
  • Will using GetItemExtraStrProperty on item 0 cause a problem if I added a regular tag to that item later?
Thanks

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

Re: Saving SelStart, SelLen and scroll positions

Post by Sergey Tkachenko »

As I understand, the question is how to store additional information with document in RVF format.

There are two ways to do it.

1) rve.DocProperties. This is a TStringList. It is saved and loaded in RVF if you include rvfoSaveDocProperties and rvfoLoadDocProperties in rve.RVFOptions.
DocProperties is a string list.
You can fill it as
rve.DocProperties.Values['SelStart'] := SelStart.ToString;

2) rve.DocObjects. This is a collection of items that may have different types, but must be inherited from TRVDocObject. It is saved and loaded in RVF if you include rvfoSaveDocObjects and rvfoLoadDocObjects in rve.RVFOptions.
The object may be define like this:

Code: Select all

type
  TRVMyDocObject = class (TRVDocObject)
  private
    FSelStart, FSelLen, FVScroll: Integer;
  published
   property SelStart: Integer read FSelStart write FSelStart;
   property SelLen: Integer read FSelLen write FSelLen;
   property VScroll: Integer read FVScroll write FVScroll;
end;
Before saving, check items of rve.DocObjects. If this collection contains item of TRVMyDocObject class, modify its properties.
If not, create a new object:

Code: Select all

var
  MyDocObj: TRVMyDocObject;

MyDocObj := TRVMyDocObject.Create(rve.DocObjects);
and assign its properties.
After loading RVF, check items of rve.DocObjects, whether this collection contains item of TRVMyDocObject class.
standay
Posts: 274
Joined: Fri Jun 18, 2021 3:07 pm

Re: Saving SelStart, SelLen and scroll positions

Post by standay »

Thanks Sergey, looks like doc properties should work. I'll try it soon.

Edit: Yes, the doc properties worked great. MUCH better than what I was doing. Thanks!

Stan
Post Reply