[fpc-devel] Which of them are right (Delphi or FPC)
vsnijders at quicknet.nl
Tue Apr 18 09:02:41 CEST 2006
Amir Aavani wrote:
> I developed a project in lazarus (FPC) and now when I try to run it in
> Delphi, it acts incorrect!
> I have a class TObjectCollection which is a collection of TObject:
> TObjectCollection= class (TObject)
> FMembers: array of TObject;
> property Member [Index: Integer]: TObject read GetMember;
> procedure Add (ANewMember: TObject);
> And A TObject1Collection which is like this:
> TObject1Collection= class (TObjectCollection)
> function GetMember: TObject1;
> property Member [Index: Integer]: TObject1 read GetMember;
> procedure Add (ANewMember: TObject1);
> procedure TObject1Collection.Add (ANewMember: TObject1);
> (Self AS TObjectCollection).Add (ANewMember AS TObject);
> procedure TObject1Collection.GetMember: TObject1;
> Result:= (Self AS TObjectCollection).Member AS TObject1;end;
> The code works correctly in lazarus, but in Delphi, the procedure
> TObject1Collection.Add call itself instead of TObjectCollection.Add. I
> changed the code like this:
> SelfAsTObjectCollection:= Self As TObjectCollection;
> SelfAsTObjectCollection.Add (ANewMember);
> and the problem solved.
> I want to know, which of us (me, Delphi, Freepascal) is wrong.
I don't know.
(Self AS TObjectCollection).Add (ANewMember AS TObject);
you could use
Inherited Add(ANewMember as TObject).
And because TObject1 inherits from TObject (at least in this example),
it can be even shorter:
I don't know if you can use inherited with propeties. I would have to
check to docs for that.
More information about the fpc-devel