mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-19 16:40:54 +02:00
IDE: added check to avoid circular frames, bug #14311
git-svn-id: trunk@21274 -
This commit is contained in:
parent
bdb9e3c022
commit
cb375e7df1
@ -1547,8 +1547,12 @@ var
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
//DebugLn(['AddComponent ',dbgsName(NewComponentClass)]);
|
//DebugLn(['AddComponent ',dbgsName(NewComponentClass)]);
|
||||||
if NewComponentClass=nil then exit;
|
if NewComponentClass = nil then exit;
|
||||||
if LookupRoot.InheritsFrom(NewComponentClass) then begin
|
|
||||||
|
// check circles
|
||||||
|
if LookupRoot.InheritsFrom(NewComponentClass) or
|
||||||
|
TheFormEditor.HasCircularDependencies(NewComponentClass, LookupRoot) then
|
||||||
|
begin
|
||||||
IDEMessageDialog(lisInvalidCircle,
|
IDEMessageDialog(lisInvalidCircle,
|
||||||
Format(lisIsAThisCircleDependencyIsNotAllowed, [dbgsName(LookupRoot),
|
Format(lisIsAThisCircleDependencyIsNotAllowed, [dbgsName(LookupRoot),
|
||||||
dbgsName(NewComponentClass), #13]),
|
dbgsName(NewComponentClass), #13]),
|
||||||
|
@ -256,6 +256,7 @@ each control that's dropped onto the form
|
|||||||
var Ancestor, RootAncestor: TComponent);
|
var Ancestor, RootAncestor: TComponent);
|
||||||
procedure SetComponentNameAndClass(CI: TIComponentInterface;
|
procedure SetComponentNameAndClass(CI: TIComponentInterface;
|
||||||
const NewName, NewClassName: shortstring);
|
const NewName, NewClassName: shortstring);
|
||||||
|
function HasCircularDependencies(AClass: TComponentClass; AComponent: TComponent): Boolean;
|
||||||
|
|
||||||
// ancestors
|
// ancestors
|
||||||
function GetAncestorLookupRoot(AComponent: TComponent): TComponent; override;
|
function GetAncestorLookupRoot(AComponent: TComponent): TComponent; override;
|
||||||
@ -1840,6 +1841,33 @@ begin
|
|||||||
AComponent.Name:=NewName;
|
AComponent.Name:=NewName;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function TCustomFormEditor.HasCircularDependencies(AClass: TComponentClass; AComponent: TComponent): Boolean;
|
||||||
|
|
||||||
|
function HasChild(WhatToTraverse, WhatToSearch: TComponent): Boolean;
|
||||||
|
var
|
||||||
|
i: integer;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
for i := 0 to WhatToTraverse.ComponentCount - 1 do
|
||||||
|
begin
|
||||||
|
Result := WhatToTraverse.Components[i].InheritsFrom(WhatToSearch.ClassType) or
|
||||||
|
HasChild(WhatToTraverse.Components[i], WhatToSearch);
|
||||||
|
if Result then Exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
AnUnitInfo: TUnitInfo;
|
||||||
|
Cmp: TComponent;
|
||||||
|
begin
|
||||||
|
Result := False;
|
||||||
|
AnUnitInfo := Project1.UnitWithComponentClass(AClass);
|
||||||
|
if AnUnitInfo = nil then Exit;
|
||||||
|
Cmp := AnUnitInfo.Component;
|
||||||
|
if Cmp = nil then Exit;
|
||||||
|
Result := HasChild(Cmp, AComponent);
|
||||||
|
end;
|
||||||
|
|
||||||
function TCustomFormEditor.GetAncestorLookupRoot(AComponent: TComponent
|
function TCustomFormEditor.GetAncestorLookupRoot(AComponent: TComponent
|
||||||
): TComponent;
|
): TComponent;
|
||||||
var
|
var
|
||||||
|
Loading…
Reference in New Issue
Block a user