Merge branch 'IdeProject/IndexOfUnit' into 'main'

IdeProject: Refactoring the IndexOfUnitWith* functions of the TProject class

See merge request freepascal.org/lazarus/lazarus!394
This commit is contained in:
n7800 2025-03-29 09:09:53 +00:00
commit 9a499afd13

View File

@ -4260,51 +4260,62 @@ end;
function TProject.IndexOfUnitWithName(const AnUnitName: string;
OnlyProjectUnits: boolean; IgnoreUnit: TUnitInfo): integer;
var
lUnit: TUnitInfo;
begin
if AnUnitName='' then exit(-1);
Result:=UnitCount-1;
while (Result>=0) do begin
if (Units[Result].IsPartOfProject or not OnlyProjectUnits)
and (IgnoreUnit<>Units[Result])
and (Units[Result].Unit_Name<>'')
then begin
if (CompareDottedIdentifiers(PChar(Units[Result].Unit_Name),PChar(AnUnitName))=0)
then
exit;
end;
dec(Result);
//if AnUnitName = '' then
// exit(-1);
for result := UnitCount - 1 downto 0 do
begin
lUnit := Units[result];
if lUnit = IgnoreUnit then continue;
if OnlyProjectUnits and not lUnit.IsPartOfProject then continue;
if lUnit.Unit_Name = '' then continue;
if CompareDottedIdentifiers(PChar(lUnit.Unit_Name), PChar(AnUnitName)) = 0 then
exit;
end;
result := -1;
end;
function TProject.IndexOfUnitWithComponent(AComponent: TComponent;
OnlyProjectUnits: boolean; IgnoreUnit: TUnitInfo): integer;
var
lUnit: TUnitInfo;
begin
Result:=UnitCount-1;
while (Result>=0) do begin
if (Units[Result].IsPartOfProject or not OnlyProjectUnits)
and (IgnoreUnit<>Units[Result]) then begin
if Units[Result].Component=AComponent then
exit;
end;
dec(Result);
//if AComponent = nil then
// exit(-1);
for result := UnitCount - 1 downto 0 do
begin
lUnit := Units[result];
if lUnit = IgnoreUnit then continue;
if OnlyProjectUnits and not lUnit.IsPartOfProject then continue;
if lUnit.Component = AComponent then
exit;
end;
result := -1;
end;
function TProject.IndexOfUnitWithComponentName(const AComponentName: string;
OnlyProjectUnits: boolean; IgnoreUnit: TUnitInfo): integer;
var
lUnit: TUnitInfo;
begin
Result:=UnitCount-1;
while (Result>=0) do begin
if (Units[Result].IsPartOfProject or not OnlyProjectUnits)
and (IgnoreUnit<>Units[Result]) then begin
if (CompareText(Units[Result].ComponentName,AComponentName)=0)
or ((Units[Result].Component<>nil)
and (CompareText(Units[Result].Component.Name,AComponentName)=0))
then
exit;
end;
dec(Result);
//if AComponentName = '' then
// exit(-1);
for result := UnitCount - 1 downto 0 do
begin
lUnit := Units[result];
if lUnit = IgnoreUnit then continue;
if OnlyProjectUnits and not lUnit.IsPartOfProject then continue;
if CompareText(lUnit.ComponentName, AComponentName) = 0 then
exit;
if assigned(lUnit.Component) and (CompareText(lUnit.Component.Name, AComponentName) = 0) then
exit;
end;
result := -1;
end;
function TProject.UnitWithEditorComponent(AEditor: TSourceEditorInterface): TUnitInfo;