IDE: Refactoring, move identical code to a procedure.

git-svn-id: trunk@54320 -
This commit is contained in:
juha 2017-03-01 16:16:57 +00:00
parent faf1054d64
commit 522a0f5505

View File

@ -5187,18 +5187,39 @@ var
UnitFilenames: TStrings; UnitFilenames: TStrings;
ComponentNameToUnitFilename: TStringToStringTree; ComponentNameToUnitFilename: TStringToStringTree;
procedure AddFile(List: TStrings; aFilename: string); procedure AddFile(aFilename: string);
var var
i: Integer; i: Integer;
begin begin
for i:=0 to List.Count-1 do for i:=0 to UnitFilenames.Count-1 do
if CompareFilenames(List[i],aFilename)=0 then exit; if CompareFilenames(UnitFilenames[i],aFilename)=0 then exit;
List.Add(aFilename); UnitFilenames.Add(aFilename);
end;
procedure SearchFromSource(aUnitInfo: TUnitInfo);
var
CurUnitFilenames: TStrings;
CTResult: Boolean;
i: Integer;
begin
CurUnitFilenames:=nil;
try
CTResult:=CodeToolBoss.FindUsedUnitFiles(aUnitInfo.Source, CurUnitFilenames);
if not CTResult then begin
DebugLn(['Error: (lazarus) [TMainIDE.DoFixupComponentReferences.FindUsedUnits] failed parsing ',
aUnitInfo.Filename]);
// ignore the error. This was just a fallback search.
end;
if (CurUnitFilenames<>nil) then
for i:=0 to CurUnitFilenames.Count-1 do
AddFile(CurUnitFilenames[i]);
finally
CurUnitFilenames.Free;
end;
end; end;
procedure FindUsedUnits; procedure FindUsedUnits;
var var
CurUnitFilenames: TStrings;
i: Integer; i: Integer;
UnitFilename: string; UnitFilename: string;
LFMFilename: String; LFMFilename: String;
@ -5207,49 +5228,20 @@ var
LFMComponentName: String; LFMComponentName: String;
LFMClassName: String; LFMClassName: String;
ModalResult: TModalResult; ModalResult: TModalResult;
CTResult: Boolean;
begin begin
if UnitFilenames<>nil then exit; if UnitFilenames<>nil then exit;
UnitFilenames:=TStringList.Create; UnitFilenames:=TStringList.Create;
ComponentNameToUnitFilename:=TStringToStringTree.Create(false); ComponentNameToUnitFilename:=TStringToStringTree.Create(false);
// search in the used units of RootUnitInfo // search in the used units of RootUnitInfo
CurUnitFilenames:=nil; SearchFromSource(RootUnitInfo);
try
CTResult:=CodeToolBoss.FindUsedUnitFiles(RootUnitInfo.Source,CurUnitFilenames);
if not CTResult then begin
DebugLn(['Error: (lazarus) [TMainIDE.DoFixupComponentReferences.FindUsedUnits] failed parsing ',RootUnitInfo.Filename]);
// ignore the error. This was just a fallback search.
end;
if (CurUnitFilenames<>nil) then begin
for i:=0 to CurUnitFilenames.Count-1 do
AddFile(UnitFilenames,CurUnitFilenames[i]);
end;
finally
CurUnitFilenames.Free;
end;
// search in the used units of the .lpr file // search in the used units of the .lpr file
if RootUnitInfo.IsPartOfProject if RootUnitInfo.IsPartOfProject
and (Project1.MainUnitInfo<>nil) and (Project1.MainUnitInfo<>nil)
and (Project1.MainUnitInfo.Source<>nil) and (Project1.MainUnitInfo.Source<>nil)
and (pfMainUnitIsPascalSource in Project1.Flags) then begin and (pfMainUnitIsPascalSource in Project1.Flags)
CurUnitFilenames:=nil; then
try SearchFromSource(Project1.MainUnitInfo);
CTResult:=CodeToolBoss.FindUsedUnitFiles(Project1.MainUnitInfo.Source,
CurUnitFilenames);
if not CTResult then begin
DebugLn(['Error: (lazarus) [TMainIDE.DoFixupComponentReferences.FindUsedUnits] failed parsing ',Project1.MainUnitInfo.Filename]);
// ignore the error. This was just a fallback search.
end;
if (CurUnitFilenames<>nil) then begin
for i:=0 to CurUnitFilenames.Count-1 do
AddFile(UnitFilenames,CurUnitFilenames[i]);
end;
finally
CurUnitFilenames.Free;
end;
end;
// parse once all available component names in all .lfm files // parse once all available component names in all .lfm files
for i:=0 to UnitFilenames.Count-1 do begin for i:=0 to UnitFilenames.Count-1 do begin