IDE: Identify dead code under SearchComponentClass by assertions, remove TryRegisteredClasses. If not triggered, the code can be removed. Remove TryRegisteredClasses.

This commit is contained in:
Juha 2021-11-29 12:03:17 +02:00
parent 04781797a3
commit 07a4f62dd0

View File

@ -6581,36 +6581,6 @@ var
Result:=true; Result:=true;
end; end;
function TryRegisteredClasses(aClassName: string;
out FoundComponentClass: TComponentClass;
out TheModalResult: TModalResult): boolean;
var
RegComp: TRegisteredComponent;
begin
{$IFDEF VerboseLFMSearch}
debugln([' TryRegisteredClasses aClassName="',aClassName,'"']);
{$ENDIF}
Result:=false;
TheModalResult:=mrCancel;
FoundComponentClass:=nil;
if AnUnitInfo.UnitResourceFileformat<>nil then
FoundComponentClass:=AnUnitInfo.UnitResourceFileformat.FindComponentClass(aClassName);
if FoundComponentClass=nil then
begin
RegComp:=IDEComponentPalette.FindRegComponent(aClassName);
if (RegComp<>nil) and
not RegComp.ComponentClass.InheritsFrom(TCustomFrame) then // Nested TFrame
FoundComponentClass:=RegComp.ComponentClass;
end;
if FoundComponentClass=nil then
FoundComponentClass:=FormEditor1.FindDesignerBaseClassByName(aClassName,true);
if FoundComponentClass<>nil then begin
DebugLn(['SearchComponentClass.TryRegisteredClasses found: ',FoundComponentClass.ClassName]);
TheModalResult:=mrOk;
Result:=true;
end;
end;
function TryLFM(const UnitFilename, AClassName: string; function TryLFM(const UnitFilename, AClassName: string;
out TheModalResult: TModalResult): boolean; out TheModalResult: TModalResult): boolean;
var var
@ -6811,13 +6781,11 @@ var
if TryUnitComponent(NewTool.MainFilename,TheModalResult) then if TryUnitComponent(NewTool.MainFilename,TheModalResult) then
exit(true); exit(true);
// try lfm // try lfm (dead, can be removed)
if TryLFM(NewTool.MainFilename,AComponentClassName,TheModalResult) then if TryLFM(NewTool.MainFilename,AComponentClassName,TheModalResult) then begin
exit(true); Assert(False, 'TryFindDeclaration: TryLFM returned True!');
// search ancestor in registered classes
if TryRegisteredClasses(AncestorClassName,AncestorClass,TheModalResult) then
exit(true); exit(true);
end;
{$IFDEF VerboseLFMSearch} {$IFDEF VerboseLFMSearch}
debugln(['TryFindDeclaration declaration of ',AComponentClassName,' found at ',NewTool.CleanPosToStr(NewNode.StartPos),' Ancestor="',AncestorClassName,'", but no lfm and no registered class found']); debugln(['TryFindDeclaration declaration of ',AComponentClassName,' found at ',NewTool.CleanPosToStr(NewNode.StartPos),' Ancestor="',AncestorClassName,'", but no lfm and no registered class found']);
@ -6864,8 +6832,6 @@ var
exit; exit;
end; end;
StoreComponentClassDeclaration(UnitFilename); StoreComponentClassDeclaration(UnitFilename);
if TryRegisteredClasses(AncestorClassName,AncestorClass,TheModalResult) then
exit(true);
end; end;
var var
@ -6897,9 +6863,6 @@ begin
if TryUnitComponent(AnUnitInfo.Filename,Result) then exit; if TryUnitComponent(AnUnitInfo.Filename,Result) then exit;
end; end;
// then try registered global classes
if TryRegisteredClasses(AComponentClassName,AComponentClass,Result) then exit;
// search in used units // search in used units
UsedUnitFilenames:=nil; UsedUnitFilenames:=nil;
try try
@ -6917,7 +6880,8 @@ begin
if (UsedUnitFilenames<>nil) then begin if (UsedUnitFilenames<>nil) then begin
// search every used unit for .lfm file. The list is backwards, last unit first. // search every used unit for .lfm file. The list is backwards, last unit first.
for i:=0 to UsedUnitFilenames.Count-1 do begin for i:=0 to UsedUnitFilenames.Count-1 do begin
if TryLFM(UsedUnitFilenames[i],AComponentClassName,Result) then exit; if TryLFM(UsedUnitFilenames[i],AComponentClassName,Result) then
exit;
end; end;
// search class via codetools // search class via codetools
if TryFindDeclaration(Result) then exit; if TryFindDeclaration(Result) then exit;
@ -6970,7 +6934,7 @@ function LoadComponentDependencyHidden(AnUnitInfo: TUnitInfo;
not found, user wants to skip this step and continue not found, user wants to skip this step and continue
} }
function TryLFM(LFMFilename: string): TModalResult; function TryDepLFM(LFMFilename: string): TModalResult;
var var
UnitFilename: String; UnitFilename: String;
CurUnitInfo: TUnitInfo; CurUnitInfo: TUnitInfo;
@ -6983,7 +6947,7 @@ function LoadComponentDependencyHidden(AnUnitInfo: TUnitInfo;
Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],true); Result:=LoadCodeBuffer(LFMCode,LFMFilename,[lbfCheckIfText],true);
if Result<>mrOk then begin if Result<>mrOk then begin
{$IFDEF VerboseLFMSearch} {$IFDEF VerboseLFMSearch}
debugln([' TryLFM LoadCodeBuffer failed ',LFMFilename]); debugln([' TryDepLFM LoadCodeBuffer failed ',LFMFilename]);
{$ENDIF} {$ENDIF}
exit; exit;
end; end;
@ -7015,7 +6979,7 @@ function LoadComponentDependencyHidden(AnUnitInfo: TUnitInfo;
if SysUtils.CompareText(CurUnitInfo.Component.ClassName,LFMClassName)<>0 if SysUtils.CompareText(CurUnitInfo.Component.ClassName,LFMClassName)<>0
then begin then begin
{$IFDEF VerboseLFMSearch} {$IFDEF VerboseLFMSearch}
debugln([' TryLFM ERROR lfmclass=',LFMClassName,' unit.component=',DbgSName(CurUnitInfo.Component)]); debugln([' TryDepLFM ERROR lfmclass=',LFMClassName,' unit.component=',DbgSName(CurUnitInfo.Component)]);
{$ENDIF} {$ENDIF}
IDEMessageDialog('Error','Unable to load "'+LFMFilename+'".' IDEMessageDialog('Error','Unable to load "'+LFMFilename+'".'
+' The component '+DbgSName(CurUnitInfo.Component) +' The component '+DbgSName(CurUnitInfo.Component)
@ -7095,7 +7059,7 @@ begin
// componentclass does not exist, but the ancestor is a registered class // componentclass does not exist, but the ancestor is a registered class
if (Result=mrOk) and (AComponentClass=nil) and (LFMFilename<>'') then if (Result=mrOk) and (AComponentClass=nil) and (LFMFilename<>'') then
exit(TryLFM(LFMFilename)); exit(TryDepLFM(LFMFilename));
if MustHaveLFM and (AComponentClass=nil) then if MustHaveLFM and (AComponentClass=nil) then
Result:=mrCancel; Result:=mrCancel;