Move Selection to Original Position

General TRichView support forum. Please post your questions here
lkessler
Posts: 112
Joined: Thu Sep 01, 2005 9:00 pm
Location: Winnipeg, Manitoba, Canada
Contact:

Post by lkessler »

Thank you again Sergey. I've got it now!

For your reference I am using Delphi 2009. I'm compiling with Debug options.

When I used your new code, I again got an Access Violation exception at run time, this time on the "Count := 0" line. I don't develop components or classes so I have no idea why this might be.

What I did to get around it was to eliminate the TRVSelection type, and just declare the private variables of that class locally, and I took the "TRVSelection." off the GetFromRichViewEdit and SetToRichViewEdit procedure names.

After I did this, then it starting running correctly. Hooray!

Once it reached a table, it then gave me a runtime exception: "Invalid Class Type cast". It didn't like the two "as TRVTableItemInfo" typecasts, so I changed them to an "as TCustomRVItemInfo" and enclosed them within a "TRVTableItemInfo(...)" cast. That worked.

Finally to complete this, if I added or deleted items prior to the selection (and for me these are ALWAYS items at the top level, i.e. never in a table), I had to add the following between the GetFromRichViewEdit and SetToRichViewEdit:

Code: Select all

    NumChange := NumItemsAdded - NumItemsDeleted;
    if NumChange <> 0 then begin
      if SelDepth = 0 then begin  { Not within a table }
        SelStartNo := SelStartNo + NumChange;
        SelEndNo := SelEndNo + NumChange;
      end
      else { Within a table }
        TableItemNoArr[0] := TableItemNoArr[0] + NumChange;
    end;
So I'm extremely happy, because I was looking at this for several weeks very confused. After I see your code I can do it, but I would never have done it without your help.

Thanks so much for your great support, Sergey. It's been 10 years since I purchased RichView 1.2 from you. ... and I'm still only in Beta release of my program. :( But I'm on a roll now and hopefully version 1 will be out before the summer. :D
Sergey Tkachenko
Site Admin
Posts: 17555
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I think the reason for all these errors is very simple: you did not create an object.
Before using, call

Code: Select all

CurrentSelection := TRVSelection.Create;
After using, free it:

Code: Select all

CurrentSelection.Free;
lkessler
Posts: 112
Joined: Thu Sep 01, 2005 9:00 pm
Location: Winnipeg, Manitoba, Canada
Contact:

Post by lkessler »

Yes, of course. Thank you Sergey.

If you add this procedure to your examples, you might want to make the typecast change.
Post Reply