I need to find the first and the last, for that I have performed the following functions:
function TForm1.FindLastTxt(searchtxt:string) : boolean;
var
foundWorksheet: TsWorksheet;
MySearchParams: TsSearchParams;
tmpfind: Boolean;
begin
foundRow:=0;
foundCol:=0;
tmpfind:=False;
MySearchParams.SearchText := searchtxt;
MySearchParams.Options := [soCompareEntireCell,soEntireDocument];
MySearchParams.Within := swWorksheet;
with TsSearchEngine.Create(sWGrid.Workbook) do begin
if FindFirst(MySearchParams, foundWorksheet, foundRow, foundCol) then
begin
while FindNext(MySearchParams, foundWorksheet, foundRow, foundCol) do
begin
tmpfind:=True;
end;
end;
Free;
end;
Result:=tmpfind;
end;
function TForm1.FindFirstTxt(searchtxt:string) : boolean;
var
foundWorksheet: TsWorksheet;
MySearchParams: TsSearchParams;
tmpfind: Boolean;
begin
foundRow:=0;
foundCol:=0;
tmpfind:=False;
MySearchParams.SearchText := searchtxt;
MySearchParams.Options := [soCompareEntireCell,soEntireDocument];
MySearchParams.Within := swWorksheet;
with TsSearchEngine.Create(sWGrid.Workbook) do begin
if FindFirst(MySearchParams, foundWorksheet, foundRow, foundCol) then
begin
tmpfind:=True;
end;
Free;
end;
Result:=tmpfind;
end;
Where,
var
Form1: TForm1;
foundRow, foundCol: Cardinal;
With FindFirstTxt: Successfully selects the first cell found and returns foundRow and foundCol successfully.
With FindLastTxt: selects the last found cell correctly, but returns foundRow and foundCol with incorrect values.
I attach an image and the code of the test program.
I appreciate the help you can give me.