Get the Item for a Tag

General TRichView support forum. Please post your questions here
Post Reply
calivers
Posts: 2
Joined: Thu Sep 01, 2005 3:57 pm

Get the Item for a Tag

Post by calivers »

Hello

I have a Tag-Value (Id) and want to find the Item for it.
I use the following procdure to get it.
My Question is, is there a faster way than to iterate throuh
the items ?

Code: Select all

function GetItemNum(Id: Integer): Integer;
var
  i: Integer;
begin
  Result := -1;
  if RV.GetCurrentTag = Id then
  begin
    Result := RV.CurItemNo;
  end else begin
    for i := 0 to RV.ItemCount - 1 do
    begin
      if RV.GetItemTag(i) = Id then
      begin
        Result := i;
        Exit;
      end;
    end;
  end;
end;
Thanks Calivers
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

No, this is the fastest method.
Of course, you code works as expected only if tags are integer values (if not, you should compare strings referenced by tags instead)

But your method will not find items inside table cells, because they are not included in the items of main document. Moreover, if the caret is inside table cell, the RV.GetCurrentTag returns the tag of the item inside table cell, but RV.CurItemNo returns the item index of table.
Does you application use tables?
Guest

Post by Guest »

No, it's a plain text-editor with some highlighting.

Thanks for your answer.
Sergey Tkachenko
Site Admin
Posts: 17310
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Then for any case, compile your application with RVDONOTUSETABLES compiler define (Project | Options, Directories/Conditionals, Conditional defines; of course, you need a source code version of TRichView to make it work). All table-related code will be excluded from your application, and users will not be able to copy-paste tables from another application. Besides, exe file size will be smaller.
Post Reply