mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-22 16:39:15 +02:00
IDE: fixed crashing componenttreeview while destroying components
git-svn-id: trunk@25460 -
This commit is contained in:
parent
6f703c73b1
commit
6be124b946
@ -300,7 +300,7 @@ function CompareDefPropCacheItems(Item1, Item2: TDefinePropertiesCacheItem): int
|
|||||||
function ComparePersClassNameAndDefPropCacheItem(Key: Pointer;
|
function ComparePersClassNameAndDefPropCacheItem(Key: Pointer;
|
||||||
Item: TDefinePropertiesCacheItem): integer;
|
Item: TDefinePropertiesCacheItem): integer;
|
||||||
|
|
||||||
function TryFreeComponent(var obj): boolean;
|
function TryFreeComponent(var AComponent: TComponent): boolean;
|
||||||
|
|
||||||
procedure RegisterStandardClasses;
|
procedure RegisterStandardClasses;
|
||||||
|
|
||||||
@ -327,18 +327,19 @@ begin
|
|||||||
RegisterClasses([TStringList]);
|
RegisterClasses([TStringList]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TryFreeComponent(var obj): boolean;
|
function TryFreeComponent(var AComponent: TComponent): boolean;
|
||||||
var
|
var
|
||||||
OldName, OldClassName: string;
|
OldName, OldClassName: string;
|
||||||
AComponent: TComponent absolute obj;
|
|
||||||
Begin
|
Begin
|
||||||
Result := False;
|
Result := False;
|
||||||
|
//debugln(['TryFreeComponent ',DbgSName(AComponent)]);
|
||||||
{$IFNDEF NoCompCatch}
|
{$IFNDEF NoCompCatch}
|
||||||
try
|
try
|
||||||
{$ENDIF}
|
{$ENDIF}
|
||||||
OldName := AComponent.Name;
|
OldName := AComponent.Name;
|
||||||
OldClassName := AComponent.ClassName;
|
OldClassName := AComponent.ClassName;
|
||||||
AComponent.Free;
|
AComponent.Free;
|
||||||
|
//debugln(['TryFreeComponent ',OldName,':',OldClassName,' success']);
|
||||||
Result := True;
|
Result := True;
|
||||||
{$IFNDEF NoCompCatch}
|
{$IFNDEF NoCompCatch}
|
||||||
except
|
except
|
||||||
@ -370,31 +371,6 @@ Begin
|
|||||||
AComponent := nil;
|
AComponent := nil;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{function TComponentInterface.Focus : Boolean;
|
|
||||||
begin
|
|
||||||
Result := False;
|
|
||||||
if (FComponent is TWinControl) and (TWinControl(FComponent).CanFocus) then
|
|
||||||
Begin
|
|
||||||
TWinControl(FComponent).SetFocus;
|
|
||||||
Result := True;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TComponentInterface.Delete: Boolean;
|
|
||||||
begin
|
|
||||||
Result:=TryFreeComponent(FComponent);
|
|
||||||
Free;
|
|
||||||
end;
|
|
||||||
|
|
||||||
function TComponentInterface.GetComponentEditor: TBaseComponentEditor;
|
|
||||||
begin
|
|
||||||
if FComponentEditor=nil then begin
|
|
||||||
FComponentEditor:=ComponentEditors.GetComponentEditor(Component,Designer);
|
|
||||||
end;
|
|
||||||
Result:=FComponentEditor;
|
|
||||||
end;
|
|
||||||
}
|
|
||||||
|
|
||||||
{ TCustomFormEditor }
|
{ TCustomFormEditor }
|
||||||
|
|
||||||
constructor TCustomFormEditor.Create;
|
constructor TCustomFormEditor.Create;
|
||||||
@ -477,7 +453,6 @@ end;
|
|||||||
Procedure TCustomFormEditor.DeleteComponent(AComponent: TComponent;
|
Procedure TCustomFormEditor.DeleteComponent(AComponent: TComponent;
|
||||||
FreeComponent: boolean);
|
FreeComponent: boolean);
|
||||||
var
|
var
|
||||||
i: integer;
|
|
||||||
AForm: TCustomForm;
|
AForm: TCustomForm;
|
||||||
AWinControl: TWinControl;
|
AWinControl: TWinControl;
|
||||||
IsJIT: Boolean;
|
IsJIT: Boolean;
|
||||||
@ -488,16 +463,7 @@ Begin
|
|||||||
if PropertyEditorHook.LookupRoot=AComponent then
|
if PropertyEditorHook.LookupRoot=AComponent then
|
||||||
PropertyEditorHook.LookupRoot:=nil;
|
PropertyEditorHook.LookupRoot:=nil;
|
||||||
IsJIT:=IsJITComponent(AComponent);
|
IsJIT:=IsJITComponent(AComponent);
|
||||||
if IsJIT or (csInline in AComponent.ComponentState) then begin
|
if IsJIT then begin
|
||||||
i:=AComponent.ComponentCount-1;
|
|
||||||
while i>=0 do begin
|
|
||||||
DeleteComponent(AComponent.Components[i],FreeComponent);
|
|
||||||
dec(i);
|
|
||||||
if i>AComponent.ComponentCount-1 then
|
|
||||||
i:=AComponent.ComponentCount-1;
|
|
||||||
end;
|
|
||||||
end;
|
|
||||||
if IsJITComponent(AComponent) then begin
|
|
||||||
// value is a top level component
|
// value is a top level component
|
||||||
if JITFormList.IsJITForm(AComponent) then begin
|
if JITFormList.IsJITForm(AComponent) then begin
|
||||||
// free/unbind a form component
|
// free/unbind a form component
|
||||||
|
@ -13049,12 +13049,12 @@ end;
|
|||||||
|
|
||||||
procedure TMainIDE.OnDesignerPersistentDeleted(Sender: TObject;
|
procedure TMainIDE.OnDesignerPersistentDeleted(Sender: TObject;
|
||||||
APersistent: TPersistent);
|
APersistent: TPersistent);
|
||||||
|
// important: APersistent was freed, do not access it
|
||||||
var
|
var
|
||||||
CurDesigner: TDesigner;
|
CurDesigner: TDesigner;
|
||||||
begin
|
begin
|
||||||
CurDesigner := TDesigner(Sender);
|
CurDesigner := TDesigner(Sender);
|
||||||
if dfDestroyingForm in CurDesigner.Flags then exit;
|
if dfDestroyingForm in CurDesigner.Flags then exit;
|
||||||
OnControlSelectionChanged(Sender, True);
|
|
||||||
ObjectInspector1.FillPersistentComboBox;
|
ObjectInspector1.FillPersistentComboBox;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@ -155,6 +155,7 @@ var
|
|||||||
AVLNode: TAvgLvlTreeNode;
|
AVLNode: TAvgLvlTreeNode;
|
||||||
Root: TComponent;
|
Root: TComponent;
|
||||||
begin
|
begin
|
||||||
|
if csDestroying in AComponent.ComponentState then exit;
|
||||||
if GetLookupRootForComponent(AComponent) <> FRootComponent then Exit;
|
if GetLookupRootForComponent(AComponent) <> FRootComponent then Exit;
|
||||||
|
|
||||||
AVLNode := FCandidates.FindKey(AComponent, TListSortCompare(@ComparePersistentWithComponentCandidate));
|
AVLNode := FCandidates.FindKey(AComponent, TListSortCompare(@ComparePersistentWithComponentCandidate));
|
||||||
@ -222,7 +223,8 @@ begin
|
|||||||
FComponentList.Clear;
|
FComponentList.Clear;
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if not NewSelection.ForceUpdate and FComponentList.IsEqual(PropertyEditorHook.LookupRoot, NewSelection) then
|
if not NewSelection.ForceUpdate
|
||||||
|
and FComponentList.IsEqual(PropertyEditorHook.LookupRoot, NewSelection) then
|
||||||
begin
|
begin
|
||||||
// nodes ok, but maybe node values need update
|
// nodes ok, but maybe node values need update
|
||||||
UpdateComponentNodesValues;
|
UpdateComponentNodesValues;
|
||||||
@ -566,6 +568,8 @@ var
|
|||||||
walker: TComponentWalker;
|
walker: TComponentWalker;
|
||||||
Root: TComponent;
|
Root: TComponent;
|
||||||
begin
|
begin
|
||||||
|
if csDestroying in AComponent.ComponentState then exit;
|
||||||
|
//debugln(['AddChildren ',DbgSName(AComponent),' ',AComponent.ComponentCount]);
|
||||||
walker := TComponentWalker.Create(Self, Candidates, RootComponent, ANode);
|
walker := TComponentWalker.Create(Self, Candidates, RootComponent, ANode);
|
||||||
try
|
try
|
||||||
// add inline components children
|
// add inline components children
|
||||||
@ -585,7 +589,9 @@ var
|
|||||||
Candidate: TComponentCandidate;
|
Candidate: TComponentCandidate;
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
|
//debugln(['AddCandidates OwnerComponent=',DbgSName(OwnerComponent)]);
|
||||||
if OwnerComponent = nil then Exit;
|
if OwnerComponent = nil then Exit;
|
||||||
|
if csDestroying in OwnerComponent.ComponentState then exit;
|
||||||
for i := 0 to OwnerComponent.ComponentCount - 1 do
|
for i := 0 to OwnerComponent.ComponentCount - 1 do
|
||||||
begin
|
begin
|
||||||
AComponent := OwnerComponent.Components[i];
|
AComponent := OwnerComponent.Components[i];
|
||||||
@ -615,7 +621,12 @@ begin
|
|||||||
OldExpanded:=TTreeNodeExpandedState.Create(Self);
|
OldExpanded:=TTreeNodeExpandedState.Create(Self);
|
||||||
Items.Clear;
|
Items.Clear;
|
||||||
|
|
||||||
RootObject := PropertyEditorHook.LookupRoot;
|
RootObject := nil;
|
||||||
|
if PropertyEditorHook<>nil then
|
||||||
|
RootObject := PropertyEditorHook.LookupRoot;
|
||||||
|
if (RootObject is TComponent)
|
||||||
|
and (csDestroying in TComponent(RootObject).ComponentState) then
|
||||||
|
RootObject:=nil;
|
||||||
if RootObject <> nil then
|
if RootObject <> nil then
|
||||||
begin
|
begin
|
||||||
Candidates:=TAvgLvlTree.Create(TListSortCompare(@CompareComponentCandidates));
|
Candidates:=TAvgLvlTree.Create(TListSortCompare(@CompareComponentCandidates));
|
||||||
|
@ -4061,7 +4061,7 @@ begin
|
|||||||
if FUpdatingAvailComboBox then exit;
|
if FUpdatingAvailComboBox then exit;
|
||||||
FUpdatingAvailComboBox:=true;
|
FUpdatingAvailComboBox:=true;
|
||||||
if ComponentTree<>nil then
|
if ComponentTree<>nil then
|
||||||
ComponentTree.Selection:=FSelection;
|
ComponentTree.RebuildComponentNodes;
|
||||||
NewList:=TStringList.Create;
|
NewList:=TStringList.Create;
|
||||||
try
|
try
|
||||||
if (FPropertyEditorHook<>nil)
|
if (FPropertyEditorHook<>nil)
|
||||||
|
Loading…
Reference in New Issue
Block a user