* fixed strange free notification behavior of TComponent. Must be some memory corruption or so.

* replaced deprecated Include / Exclude calls

git-svn-id: trunk@13852 -
This commit is contained in:
ivost 2009-10-13 12:05:14 +00:00
parent f18a2ab69c
commit 74c09e2268
2 changed files with 38 additions and 52 deletions

View File

@ -1556,7 +1556,6 @@ type
{$endif} {$endif}
procedure WriteState(Writer: TWriter); virtual; procedure WriteState(Writer: TWriter); virtual;
constructor Create(AOwner: TComponent); virtual; constructor Create(AOwner: TComponent); virtual;
procedure BeforeDestruction; override;
destructor Destroy; override; destructor Destroy; override;
procedure DestroyComponents; procedure DestroyComponents;
procedure Destroying; procedure Destroying;

View File

@ -27,20 +27,14 @@ end;
function TComponent.IsImplementorOf (const Intf:IInterface):boolean; function TComponent.IsImplementorOf (const Intf:IInterface):boolean;
var ref : IInterfaceComponentReference; var ref : IInterfaceComponentReference;
begin begin
result:=assigned(intf) and supports(intf,IInterfaceComponentReference,ref); result:=assigned(intf) and supports(intf,IInterfaceComponentReference,ref) and (ref.getcomponent=self);
if result then
result:=ref.getcomponent=self;
end; end;
procedure TComponent.ReferenceInterface(const intf:IInterface;op:TOperation); procedure TComponent.ReferenceInterface(const intf:IInterface;op:TOperation);
var ref : IInterfaceComponentReference; var ref : IInterfaceComponentReference;
comp : TComponent;
begin begin
if assigned(intf) and supports(intf,IInterfaceComponentReference,ref) then if assigned(intf) and supports(intf,IInterfaceComponentReference,ref) then
begin ref.getcomponent.notification(self,op);
comp:=ref.getcomponent;
comp.notification(self,op);
end;
end; end;
Function TComponent.GetComponentCount: Integer; Function TComponent.GetComponentCount: Integer;
@ -57,7 +51,7 @@ Function TComponent.GetComponentIndex: Integer;
begin begin
If Assigned(FOwner) and Assigned(FOwner.FComponents) then If Assigned(FOwner) and Assigned(FOwner.FComponents) then
Result:=FOWner.FComponents.IndexOf(Self) Result:=FOwner.FComponents.IndexOf(Self)
else else
Result:=-1; Result:=-1;
end; end;
@ -91,7 +85,7 @@ Procedure TComponent.Remove(AComponent: TComponent);
begin begin
AComponent.FOwner:=Nil; AComponent.FOwner:=Nil;
If assigned(FCOmponents) then If assigned(FComponents) then
begin begin
FComponents.Remove(AComponent); FComponents.Remove(AComponent);
IF FComponents.Count=0 then IF FComponents.Count=0 then
@ -113,7 +107,7 @@ begin
begin begin
FFreeNotifies.Free; FFreeNotifies.Free;
FFreeNotifies:=nil; FFreeNotifies:=nil;
Exclude(FComponentState,csFreeNotification); FComponentState := FComponentState - [csFreeNotification];
end; end;
end; end;
end; end;
@ -124,7 +118,7 @@ Procedure TComponent.SetComponentIndex(Value: Integer);
Var Temp,Count : longint; Var Temp,Count : longint;
begin begin
If Not assigned(Fowner) then exit; If Not assigned(FOwner) then exit;
Temp:=getcomponentindex; Temp:=getcomponentindex;
If temp<0 then exit; If temp<0 then exit;
If value<0 then value:=0; If value<0 then value:=0;
@ -230,34 +224,35 @@ end;
Procedure TComponent.Loaded; Procedure TComponent.Loaded;
begin begin
Exclude(FComponentState,csLoading); FComponentState := FComponentState - [csLoading];
end; end;
Procedure TComponent.Loading; Procedure TComponent.Loading;
begin begin
Include(FComponentState,csLoading); FComponentState := FComponentState + [csLoading];
end; end;
Procedure TComponent.Notification(AComponent: TComponent; Procedure TComponent.Notification(AComponent: TComponent;
Operation: TOperation); Operation: TOperation);
Var Runner : Longint; //Var Runner : Longint;
begin begin
If (Operation=opRemove) and Assigned(FFreeNotifies) then If (Operation=opRemove) and Assigned(FFreeNotifies) then
begin begin
FFreeNotifies.Remove(AComponent); FFreeNotifies.Remove(AComponent);
If FFreeNotifies.Count=0 then If FFreeNotifies.Count=0 then
begin begin
FFreeNotifies.Free; FFreeNotifies.Free;
FFreenotifies:=Nil; FFreenotifies:=Nil;
FComponentState := FComponentState - [csFreeNotification];
end; end;
end; end;
If assigned(FComponents) then {If assigned(FComponents) then
For Runner:=0 To FComponents.Count-1 do For Runner:=0 To FComponents.Count-1 do
TComponent(FComponents.Items[Runner]).Notification(AComponent,Operation); TComponent(FComponents.Items[Runner]).Notification(AComponent,Operation);}
end; end;
@ -279,9 +274,9 @@ Var Runner : Longint;
begin begin
If Value then If Value then
Include(FComponentState,csAncestor) FComponentState := FComponentState + [csAncestor]
else else
Exclude(FCOmponentState,csAncestor); FComponentState := FComponentState - [csAncestor];
if Assigned(FComponents) then if Assigned(FComponents) then
For Runner:=0 To FComponents.Count-1 do For Runner:=0 To FComponents.Count-1 do
TComponent(FComponents.Items[Runner]).SetAncestor(Value); TComponent(FComponents.Items[Runner]).SetAncestor(Value);
@ -294,9 +289,9 @@ Var Runner : Longint;
begin begin
If Value then If Value then
Include(FComponentState,csDesigning) FComponentState := FComponentState + [csDesigning]
else else
Exclude(FComponentState,csDesigning); FComponentState := FComponentState - [csDesigning];
if Assigned(FComponents) and SetChildren then if Assigned(FComponents) and SetChildren then
For Runner:=0 To FComponents.Count - 1 do For Runner:=0 To FComponents.Count - 1 do
TComponent(FComponents.items[Runner]).SetDesigning(Value); TComponent(FComponents.items[Runner]).SetDesigning(Value);
@ -306,18 +301,18 @@ Procedure TComponent.SetDesignInstance(Value: Boolean);
begin begin
If Value then If Value then
Include(FComponentState,csDesignInstance) FComponentState := FComponentState + [csDesignInstance]
else else
Exclude(FComponentState,csDesignInstance); FComponentState := FComponentState - [csDesignInstance];
end; end;
Procedure TComponent.SetInline(Value: Boolean); Procedure TComponent.SetInline(Value: Boolean);
begin begin
If Value then If Value then
Include(FComponentState,csInline) FComponentState := FComponentState + [csInline]
else else
Exclude(FComponentState,csInline); FComponentState := FComponentState - [csInline];
end; end;
@ -354,14 +349,14 @@ end;
Procedure TComponent.Updating; Procedure TComponent.Updating;
begin begin
Include (FComponentState,csUpdating); FComponentState := FComponentState + [csUpdating];
end; end;
Procedure TComponent.Updated; Procedure TComponent.Updated;
begin begin
Exclude(FComponentState,csUpdating); FComponentState := FComponentState - [csUpdating];
end; end;
@ -424,18 +419,14 @@ begin
Destroying; Destroying;
If Assigned(FFreeNotifies) then If Assigned(FFreeNotifies) then
begin begin
I:=FFreeNotifies.Count-1; I := FFreeNotifies.Count-1;
While (I>=0) do While I >= 0 do
begin begin
C:=TComponent(FFreeNotifies.Items[I]); C:=TComponent(FFreeNotifies.Items[I]);
// Delete, so one component is not notified twice, if it is owned. FFreeNotifies.Delete(I);
FFreeNotifies.Delete(I); C.RemoveNotification(self);
C.Notification (self,opRemove); C.Notification(self,opRemove);
If (FFreeNotifies=Nil) then I:=FFreeNotifies.Count-1;
I:=0
else if (I>FFreeNotifies.Count) then
I:=FFreeNotifies.Count;
dec(i);
end; end;
FreeAndNil(FFreeNotifies); FreeAndNil(FFreeNotifies);
end; end;
@ -445,13 +436,6 @@ begin
end; end;
Procedure TComponent.BeforeDestruction;
begin
if not(csDestroying in FComponentstate) then
Destroying;
end;
Procedure TComponent.DestroyComponents; Procedure TComponent.DestroyComponents;
Var acomponent: TComponent; Var acomponent: TComponent;
@ -472,7 +456,7 @@ Var Runner : longint;
begin begin
If csDestroying in FComponentstate Then Exit; If csDestroying in FComponentstate Then Exit;
include (FComponentState,csDestroying); FComponentState := FComponentState + [csDestroying];
If Assigned(FComponents) then If Assigned(FComponents) then
for Runner:=0 to FComponents.Count-1 do for Runner:=0 to FComponents.Count-1 do
TComponent(FComponents.Items[Runner]).Destroying; TComponent(FComponents.Items[Runner]).Destroying;
@ -515,8 +499,11 @@ begin
AComponent.Notification(Self,opRemove) AComponent.Notification(Self,opRemove)
else else
begin begin
If not (Assigned(FFreeNotifies)) then If not Assigned(FFreeNotifies) then
FFreeNotifies:=TList.Create; begin
FFreeNotifies:=TList.Create;
FComponentState := FComponentState + [csFreeNotification];
end;
If FFreeNotifies.IndexOf(AComponent)=-1 then If FFreeNotifies.IndexOf(AComponent)=-1 then
begin begin
FFreeNotifies.Add(AComponent); FFreeNotifies.Add(AComponent);
@ -588,9 +575,9 @@ end;
procedure TComponent.SetSubComponent(ASubComponent: Boolean); procedure TComponent.SetSubComponent(ASubComponent: Boolean);
begin begin
if ASubComponent then if ASubComponent then
Include(FComponentStyle, csSubComponent) FComponentStyle := FComponentStyle + [csSubComponent]
else else
Exclude(FComponentStyle, csSubComponent); FComponentStyle := FComponentStyle - [csSubComponent];
end; end;