Hi Nicola,
You don't have to derive your class from IUnknown in Delphi or Kylix either, and just to clarify, as far as I am aware, they are not known as CORBA interfaces, they are just known as interfaces, while the Win32 variety are known as COM interfaces.Originally Posted by {MSX}
As mentioned you can also do this in Delphi/Kylix.Originally Posted by {MSX}
I don't think this is a Pascal specific problem, it is just that Java and C# have garbage collectors that go round freeing the stuff for you when they go out of scope. Also since there is no such concept as an IObject base class for all interfaces, that would explain why there is no Free method.Originally Posted by {MSX}
In Delphi, and I assume FreePascal, if you want to reset the interface you would need to assign nil to it.
[pascal]
var
n : INamed;
begin
n := TNamedItem.create;
n.GetName;
n := nil;
end;
[/pascal]
Without reference counting how will it know when to clean itself up?
IMHO, use interfaces, but use them for defining a cleaner object hierachy, but when it comes to your application/game use instances of the class instead.
for example:
[pascal]
type
IHuman = interface
function GetName:string;
end;
IMale = interface( IHuman )
function GetName:string;
function MaleChromosome:string;
end;
IFemale = interface( IHuman )
function GetName:string;
function FemaleChromosome:string;
end;
TChild = class( TObject, IMale, IFemale )
function GetName:string;
function MaleChromosome:string;
function FemaleChromosome:string;
end;
var
Kid : TChild ;
begin
Kid := TChild.Create;
try
Kid.GetName;
Kid.MaleChromosome;
Kid.FemaleChromosome;
finally
Kid.Free;
end;
end;
[/pascal]
Anyway, just my 2 kubits worth.
Bookmarks