Page 1 of 1

Get the Item for a Tag

Posted: Sat Sep 24, 2005 6:48 pm
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

Posted: Sun Sep 25, 2005 6:39 pm
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?

Posted: Sun Sep 25, 2005 7:19 pm
by Guest
No, it's a plain text-editor with some highlighting.

Thanks for your answer.

Posted: Mon Sep 26, 2005 9:07 am
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.