mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-28 01:37:20 +01:00
added owner check for designer created components
git-svn-id: trunk@5131 -
This commit is contained in:
parent
0788600787
commit
573f1ed8bd
@ -1135,6 +1135,7 @@ var
|
|||||||
var
|
var
|
||||||
NewParent: TComponent;
|
NewParent: TComponent;
|
||||||
NewParentControl: TWinControl;
|
NewParentControl: TWinControl;
|
||||||
|
NewComponent: TComponent;
|
||||||
begin
|
begin
|
||||||
if MouseDownComponent=nil then exit;
|
if MouseDownComponent=nil then exit;
|
||||||
|
|
||||||
@ -1143,7 +1144,6 @@ var
|
|||||||
ControlSelection.Clear;
|
ControlSelection.Clear;
|
||||||
|
|
||||||
// find a parent for the new component
|
// find a parent for the new component
|
||||||
writeln('AddComponent A ',FLookupRoot is TCustomForm);
|
|
||||||
if FLookupRoot is TCustomForm then begin
|
if FLookupRoot is TCustomForm then begin
|
||||||
if MouseDownComponent is TWinControl then
|
if MouseDownComponent is TWinControl then
|
||||||
NewParentControl:=TWinControl(MouseDownComponent)
|
NewParentControl:=TWinControl(MouseDownComponent)
|
||||||
@ -1192,19 +1192,21 @@ writeln('AddComponent A ',FLookupRoot is TCustomForm);
|
|||||||
NewCI := TComponentInterface(TheFormEditor.CreateComponent(
|
NewCI := TComponentInterface(TheFormEditor.CreateComponent(
|
||||||
ParentCI,SelectedCompClass.ComponentClass
|
ParentCI,SelectedCompClass.ComponentClass
|
||||||
,NewLeft,NewTop,NewWidth,NewHeight));
|
,NewLeft,NewTop,NewWidth,NewHeight));
|
||||||
|
if NewCI=nil then exit;
|
||||||
|
NewComponent:=NewCI.Component;
|
||||||
|
|
||||||
// set initial properties
|
// set initial properties
|
||||||
if NewCI.Component is TControl then
|
if NewComponent is TControl then
|
||||||
TControl(NewCI.Component).Visible:=true;
|
TControl(NewComponent).Visible:=true;
|
||||||
if Assigned(FOnSetDesigning) then
|
if Assigned(FOnSetDesigning) then
|
||||||
FOnSetDesigning(Self,NewCI.Component,True);
|
FOnSetDesigning(Self,NewComponent,True);
|
||||||
|
|
||||||
// tell IDE about the new component (e.g. add it to the source)
|
// tell IDE about the new component (e.g. add it to the source)
|
||||||
NotifyComponentAdded(NewCI.Component);
|
NotifyComponentAdded(NewComponent);
|
||||||
|
|
||||||
// creation completed
|
// creation completed
|
||||||
// -> select new component
|
// -> select new component
|
||||||
SelectOnlyThisComponent(TComponent(NewCI.Component));
|
SelectOnlyThisComponent(NewComponent);
|
||||||
if not (ssShift in Shift) then
|
if not (ssShift in Shift) then
|
||||||
if Assigned(FOnUnselectComponentClass) then
|
if Assigned(FOnUnselectComponentClass) then
|
||||||
// this resets the component palette to the selection tool
|
// this resets the component palette to the selection tool
|
||||||
@ -1212,7 +1214,7 @@ writeln('AddComponent A ',FLookupRoot is TCustomForm);
|
|||||||
|
|
||||||
{$IFDEF VerboseDesigner}
|
{$IFDEF VerboseDesigner}
|
||||||
writeln('NEW COMPONENT ADDED: Form.ComponentCount=',Form.ComponentCount,
|
writeln('NEW COMPONENT ADDED: Form.ComponentCount=',Form.ComponentCount,
|
||||||
' NewCI.Control.Owner.Name=',NewCI.Component.Owner.Name);
|
' NewComponent.Owner.Name=',NewComponent.Owner.Name);
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
|||||||
@ -908,24 +908,51 @@ Var
|
|||||||
Temp: TComponentInterface;
|
Temp: TComponentInterface;
|
||||||
NewJITIndex: Integer;
|
NewJITIndex: Integer;
|
||||||
CompLeft, CompTop, CompWidth, CompHeight: integer;
|
CompLeft, CompTop, CompWidth, CompHeight: integer;
|
||||||
|
NewComponent: TComponent;
|
||||||
OwnerComponent: TComponent;
|
OwnerComponent: TComponent;
|
||||||
ParentComponent: TComponent;
|
ParentComponent: TComponent;
|
||||||
JITList: TJITComponentList;
|
JITList: TJITComponentList;
|
||||||
AControl: TControl;
|
AControl: TControl;
|
||||||
|
NewComponentName: String;
|
||||||
Begin
|
Begin
|
||||||
|
Result:=nil;
|
||||||
|
Temp:=nil;
|
||||||
|
try
|
||||||
writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+'''');
|
writeln('[TCustomFormEditor.CreateComponent] Class='''+TypeClass.ClassName+'''');
|
||||||
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TCustomFormEditor.CreateComponent A');{$ENDIF}
|
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TCustomFormEditor.CreateComponent A');{$ENDIF}
|
||||||
Temp := TComponentInterface.Create;
|
|
||||||
|
|
||||||
OwnerComponent:=nil;
|
OwnerComponent:=nil;
|
||||||
if Assigned(ParentCI) then
|
if Assigned(ParentCI) then
|
||||||
begin
|
begin
|
||||||
// add as child control
|
// add as child component
|
||||||
ParentComponent:=TComponentInterface(ParentCI).Component;
|
ParentComponent:=TComponentInterface(ParentCI).Component;
|
||||||
OwnerComponent:=ParentComponent;
|
OwnerComponent:=ParentComponent;
|
||||||
if OwnerComponent.Owner<>nil then
|
if OwnerComponent.Owner<>nil then
|
||||||
OwnerComponent:=OwnerComponent.Owner;
|
OwnerComponent:=OwnerComponent.Owner;
|
||||||
Temp.FComponent := TypeClass.Create(OwnerComponent);
|
try
|
||||||
|
NewComponent := TypeClass.Create(OwnerComponent);
|
||||||
|
except
|
||||||
|
on e: Exception do begin
|
||||||
|
MessageDlg('Error creating component',
|
||||||
|
'Error creating component: '+TypeClass.ClassName,
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
// check if Owner was properly set
|
||||||
|
if NewComponent.Owner<>OwnerComponent then begin
|
||||||
|
MessageDlg('Invalid component owner',
|
||||||
|
'The component of type '+NewComponent.ClassName
|
||||||
|
+' failed to set its owner to '
|
||||||
|
+OwnerComponent.Name+':'+OwnerComponent.ClassName,
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
|
||||||
|
// create component interface
|
||||||
|
Temp := TComponentInterface.Create;
|
||||||
|
Temp.FComponent:=NewComponent;
|
||||||
|
|
||||||
// set parent
|
// set parent
|
||||||
if Temp.IsTControl then begin
|
if Temp.IsTControl then begin
|
||||||
if (ParentComponent is TWinControl)
|
if (ParentComponent is TWinControl)
|
||||||
@ -948,16 +975,30 @@ Begin
|
|||||||
if JITList=nil then
|
if JITList=nil then
|
||||||
RaiseException('TCustomFormEditor.CreateComponent '+TypeClass.ClassName);
|
RaiseException('TCustomFormEditor.CreateComponent '+TypeClass.ClassName);
|
||||||
NewJITIndex := JITList.AddNewJITComponent;
|
NewJITIndex := JITList.AddNewJITComponent;
|
||||||
if NewJITIndex >= 0 then
|
if NewJITIndex >= 0 then begin
|
||||||
|
// create component interface
|
||||||
|
Temp := TComponentInterface.Create;
|
||||||
Temp.FComponent := JITList[NewJITIndex]
|
Temp.FComponent := JITList[NewJITIndex]
|
||||||
else begin
|
end else begin
|
||||||
Result:=nil;
|
|
||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TCustomFormEditor.CreateComponent D ');{$ENDIF}
|
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TCustomFormEditor.CreateComponent D ');{$ENDIF}
|
||||||
Temp.Component.Name := CreateUniqueComponentName(Temp.Component);
|
try
|
||||||
|
NewComponentName := CreateUniqueComponentName(Temp.Component);
|
||||||
|
Temp.Component.Name := NewComponentName;
|
||||||
|
except
|
||||||
|
on e: Exception do begin
|
||||||
|
MessageDlg('Error naming component',
|
||||||
|
'Error setting the name of a component '
|
||||||
|
+Temp.Component.Name+':'+Temp.Component.ClassName
|
||||||
|
+' to '+NewComponentName,
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
try
|
||||||
// set bounds
|
// set bounds
|
||||||
CompLeft:=X;
|
CompLeft:=X;
|
||||||
CompTop:=Y;
|
CompTop:=Y;
|
||||||
@ -1008,6 +1049,15 @@ Begin
|
|||||||
Hi:=word(Min(32000,CompTop));
|
Hi:=word(Min(32000,CompTop));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
except
|
||||||
|
on e: Exception do begin
|
||||||
|
MessageDlg('Error moving component',
|
||||||
|
'Error moving component '
|
||||||
|
+Temp.Component.Name+':'+Temp.Component.ClassName,
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
exit;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TCustomFormEditor.CreateComponent F ');{$ENDIF}
|
{$IFDEF IDE_MEM_CHECK}CheckHeapWrtMemCnt('TCustomFormEditor.CreateComponent F ');{$ENDIF}
|
||||||
// add to component list
|
// add to component list
|
||||||
@ -1017,6 +1067,27 @@ Begin
|
|||||||
CreateChildComponentInterfaces(Temp.Component.Owner);
|
CreateChildComponentInterfaces(Temp.Component.Owner);
|
||||||
|
|
||||||
Result := Temp;
|
Result := Temp;
|
||||||
|
finally
|
||||||
|
// clean up carefully
|
||||||
|
if Result=nil then begin
|
||||||
|
if Temp=nil then begin
|
||||||
|
if NewComponent<>nil then begin
|
||||||
|
try
|
||||||
|
NewComponent.Free;
|
||||||
|
NewComponent:=nil;
|
||||||
|
except
|
||||||
|
MessageDlg('Error destroying component',
|
||||||
|
'Error destroying component of type '+TypeClass.ClassName,
|
||||||
|
mtError,[mbCancel],0);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
if (Result<>Temp) then begin
|
||||||
|
Temp.Free;
|
||||||
|
Temp:=nil;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
Function TCustomFormEditor.CreateComponentFromStream(
|
Function TCustomFormEditor.CreateComponentFromStream(
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user