fpspreadsheet: Use a local variable for found worksheet in search_demo (https://forum.lazarus.freepascal.org/index.php/topic,50851.msg372259).

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@7595 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2020-08-03 08:40:01 +00:00
parent 810aebcd2e
commit e6fd1abf98
2 changed files with 23 additions and 14 deletions

View File

@ -1,15 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<CONFIG> <CONFIG>
<ProjectOptions> <ProjectOptions>
<Version Value="11"/> <Version Value="12"/>
<PathDelim Value="\"/> <PathDelim Value="\"/>
<General> <General>
<Flags> <Flags>
<MainUnitHasCreateFormStatements Value="False"/> <MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/> <MainUnitHasTitleStatement Value="False"/>
<CompatibilityMode Value="True"/>
</Flags> </Flags>
<SessionStorage Value="InProjectDir"/> <SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="demo_search"/> <Title Value="demo_search"/>
<UseAppBundle Value="False"/> <UseAppBundle Value="False"/>
<ResourceType Value="res"/> <ResourceType Value="res"/>
@ -57,7 +57,7 @@
</SearchPaths> </SearchPaths>
<Linking> <Linking>
<Debugging> <Debugging>
<UseExternalDbgSyms Value="True"/> <DebugInfoType Value="dsDwarf2Set"/>
</Debugging> </Debugging>
</Linking> </Linking>
</CompilerOptions> </CompilerOptions>

View File

@ -14,7 +14,8 @@ var
worksheet: TsWorksheet; worksheet: TsWorksheet;
s: String; s: String;
searchParams: TsSearchParams; searchParams: TsSearchParams;
RowFound, ColFound: Cardinal; rowFound, colFound: Cardinal;
worksheetFound: TsWorksheet;
begin begin
workbook := TsWorkbook.Create; workbook := TsWorkbook.Create;
@ -36,10 +37,12 @@ begin
// Create search engine and execute search // Create search engine and execute search
with TsSearchEngine.Create(workbook) do begin with TsSearchEngine.Create(workbook) do begin
if FindFirst(searchParams, worksheet, RowFound, ColFound) then begin if FindFirst(searchParams, worksheetFound, rowFound, colFound) then begin
WriteLn('First "', searchparams.SearchText, '" found in cell ', GetCellString(RowFound, ColFound)); WriteLn('First "', searchparams.SearchText, '" found in cell ',
while FindNext(searchParams, worksheet, RowFound, ColFound) do GetCellString(rowFound, colFound), ' of worksheet ', worksheetFound.Name);
WriteLn('Next "', searchParams.SearchText, '" found in cell ', GetCellString(RowFound, ColFound)); while FindNext(searchParams, worksheetFound, rowFound, colFound) do
WriteLn('Next "', searchParams.SearchText, '" found in cell ',
GetCellString(rowFound, colFound), ' of worksheet ', worksheetFound.Name);
end; end;
Free; Free;
end; end;
@ -47,18 +50,24 @@ begin
// Now search in comments // Now search in comments
Include(searchparams.Options, soSearchInComment); Include(searchparams.Options, soSearchInComment);
with TsSearchEngine.Create(workbook) do begin with TsSearchEngine.Create(workbook) do begin
if FindFirst(searchParams, worksheet, RowFound, ColFound) then begin if FindFirst(searchParams, worksheetFound, rowFound, colFound) then begin
WriteLn('First "', searchparams.SearchText, '" found in comment of cell ', GetCellString(RowFound, ColFound)); WriteLn('First "', searchparams.SearchText, '" found in comment of cell ',
while FindNext(searchParams, worksheet, RowFound, ColFound) do GetCellString(rowFound, colFound), ' of worksheet ', worksheetFound.Name);
WriteLn('Next "', searchParams.SearchText, '" found in comment of cell ', GetCellString(RowFound, ColFound)); while FindNext(searchParams, worksheetFound, rowFound, colFound) do
WriteLn('Next "', searchParams.SearchText, '" found in comment of cell ',
GetCellString(rowFound, colFound), ' of worksheet ', worksheetFound.Name);
end; end;
Free; Free;
end; end;
ReadLn;
finally finally
workbook.Free; workbook.Free;
end; end;
{$IFDEF MSWINDOWS}
WriteLn;
WriteLn('Press ENTER to quit...');
ReadLn;
{$ENDIF}
end. end.