IDE: fixed crashing componenttreeview while destroying components

git-svn-id: trunk@25460 -
This commit is contained in:
mattias 2010-05-16 13:28:25 +00:00
parent 6f703c73b1
commit 6be124b946
4 changed files with 20 additions and 43 deletions

View File

@ -300,7 +300,7 @@ function CompareDefPropCacheItems(Item1, Item2: TDefinePropertiesCacheItem): int
function ComparePersClassNameAndDefPropCacheItem(Key: Pointer;
Item: TDefinePropertiesCacheItem): integer;
function TryFreeComponent(var obj): boolean;
function TryFreeComponent(var AComponent: TComponent): boolean;
procedure RegisterStandardClasses;
@ -327,18 +327,19 @@ begin
RegisterClasses([TStringList]);
end;
function TryFreeComponent(var obj): boolean;
function TryFreeComponent(var AComponent: TComponent): boolean;
var
OldName, OldClassName: string;
AComponent: TComponent absolute obj;
Begin
Result := False;
//debugln(['TryFreeComponent ',DbgSName(AComponent)]);
{$IFNDEF NoCompCatch}
try
{$ENDIF}
OldName := AComponent.Name;
OldClassName := AComponent.ClassName;
AComponent.Free;
//debugln(['TryFreeComponent ',OldName,':',OldClassName,' success']);
Result := True;
{$IFNDEF NoCompCatch}
except
@ -370,31 +371,6 @@ Begin
AComponent := nil;
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 }
constructor TCustomFormEditor.Create;
@ -477,7 +453,6 @@ end;
Procedure TCustomFormEditor.DeleteComponent(AComponent: TComponent;
FreeComponent: boolean);
var
i: integer;
AForm: TCustomForm;
AWinControl: TWinControl;
IsJIT: Boolean;
@ -488,16 +463,7 @@ Begin
if PropertyEditorHook.LookupRoot=AComponent then
PropertyEditorHook.LookupRoot:=nil;
IsJIT:=IsJITComponent(AComponent);
if IsJIT or (csInline in AComponent.ComponentState) 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
if IsJIT then begin
// value is a top level component
if JITFormList.IsJITForm(AComponent) then begin
// free/unbind a form component

View File

@ -13049,12 +13049,12 @@ end;
procedure TMainIDE.OnDesignerPersistentDeleted(Sender: TObject;
APersistent: TPersistent);
// important: APersistent was freed, do not access it
var
CurDesigner: TDesigner;
begin
CurDesigner := TDesigner(Sender);
if dfDestroyingForm in CurDesigner.Flags then exit;
OnControlSelectionChanged(Sender, True);
ObjectInspector1.FillPersistentComboBox;
end;

View File

@ -155,6 +155,7 @@ var
AVLNode: TAvgLvlTreeNode;
Root: TComponent;
begin
if csDestroying in AComponent.ComponentState then exit;
if GetLookupRootForComponent(AComponent) <> FRootComponent then Exit;
AVLNode := FCandidates.FindKey(AComponent, TListSortCompare(@ComparePersistentWithComponentCandidate));
@ -222,7 +223,8 @@ begin
FComponentList.Clear;
end
else
if not NewSelection.ForceUpdate and FComponentList.IsEqual(PropertyEditorHook.LookupRoot, NewSelection) then
if not NewSelection.ForceUpdate
and FComponentList.IsEqual(PropertyEditorHook.LookupRoot, NewSelection) then
begin
// nodes ok, but maybe node values need update
UpdateComponentNodesValues;
@ -566,6 +568,8 @@ var
walker: TComponentWalker;
Root: TComponent;
begin
if csDestroying in AComponent.ComponentState then exit;
//debugln(['AddChildren ',DbgSName(AComponent),' ',AComponent.ComponentCount]);
walker := TComponentWalker.Create(Self, Candidates, RootComponent, ANode);
try
// add inline components children
@ -585,7 +589,9 @@ var
Candidate: TComponentCandidate;
i: Integer;
begin
//debugln(['AddCandidates OwnerComponent=',DbgSName(OwnerComponent)]);
if OwnerComponent = nil then Exit;
if csDestroying in OwnerComponent.ComponentState then exit;
for i := 0 to OwnerComponent.ComponentCount - 1 do
begin
AComponent := OwnerComponent.Components[i];
@ -615,7 +621,12 @@ begin
OldExpanded:=TTreeNodeExpandedState.Create(Self);
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
begin
Candidates:=TAvgLvlTree.Create(TListSortCompare(@CompareComponentCandidates));

View File

@ -4061,7 +4061,7 @@ begin
if FUpdatingAvailComboBox then exit;
FUpdatingAvailComboBox:=true;
if ComponentTree<>nil then
ComponentTree.Selection:=FSelection;
ComponentTree.RebuildComponentNodes;
NewList:=TStringList.Create;
try
if (FPropertyEditorHook<>nil)