Basic question. In Button1Click I create an interfaced object. Reference counting after creation is 0. I pass the object as an argument. Ref counting increase, decrease at the end of the function and as it 0, its getting destroyed. Do I miss something? When I create the object in the first place, I was thinking that ref counting should be 1? lListFilter is not holding a reference to the object?
type
IPersistentListFilter = Interface(IInterface)
['{57cdcf89-60ee-4b3c-99fd-177b4b98d7e5}']
procedure IncludeObject;
end;
procedure FillList(AFilter : IPersistentListFilter);
type
TPersistentListFilter = class(TInterfacedObject, IPersistentListFilter)
procedure IncludeObject;
constructor Create;
destructor Destroy; override;
end;
implementation
procedure FillList(AFilter: IPersistentListFilter);
begin
AFilter.IncludeObject;
end;
constructor TPersistentListFilter.Create;
begin
inherited;
end;
destructor TPersistentListFilter.Destroy;
begin
inherited;
end;
procedure TPersistentListFilter.IncludeObject;
begin
// do nothing
end;
procedure TForm8.Button1Click(Sender: TObject);
var
lListFilter: TPersistentListFilter;
begin
lListFilter := TPersistentListFilter.Create;
// ref count is 0
FillList(lListFilter);
// lListFilter has been destroyed
FillList(lListFilter); // --> error
end;