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 ?
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;
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?
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.