Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2006-04

Which of them are right (Delphi or FPC)

3 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Amir Aavani

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;
       ...
        ...
    public
      property Member [Index: Integer]: TObject read GetMember;
      ...
      procedure Add (ANewMember: TObject);
      ...
  end;

And A TObject1Collection which is like this:
TObject1Collection= class (TObjectCollection)

      function GetMember: TObject1;
       ...
        ...
    public
      property Member [Index: Integer]: TObject1 read GetMember;
      ...
      procedure Add (ANewMember: TObject1);
      ...
  end;
procedure TObject1Collection.Add (ANewMember: TObject1);
begin
  (Self AS TObjectCollection).Add (ANewMember AS TObject);
end;
procedure TObject1Collection.GetMember: TObject1;
begin
  Result:= (Self AS TObjectCollection).Member AS TObject1;end;
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.

Reply by email

Vincent Snijders
to Amir Aavani
Amir Aavani wrote 44 lines
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; ... ... public property Member [Index: Integer]: TObject read GetMember; ... procedure Add (ANewMember: TObject); ... end; And A TObject1Collection which is like this: TObject1Collection= class (TObjectCollection) function GetMember: TObject1; ... ... public property Member [Index: Integer]: TObject1 read GetMember; ... procedure Add (ANewMember: TObject1); ... end; procedure TObject1Collection.Add (ANewMember: TObject1); begin (Self AS TObjectCollection).Add (ANewMember AS TObject); end; procedure TObject1Collection.GetMember: TObject1; begin Result:= (Self AS TObjectCollection).Member AS TObject1;end; 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.

Instead of
   (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:

   Inherited Add(TObject).

I don't know if you can use inherited with propeties. I would have to check to docs for that.

Vincent

Reply by email

Michael Van Canneyt
to Amir Aavani: I developed a project in lazarus (FPC) and now when I try to run it in Delphi, it acts…
Amir Aavani wrote 44 lines
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; ... ... public property Member [Index: Integer]: TObject read GetMember; ... procedure Add (ANewMember: TObject); ... end; And A TObject1Collection which is like this: TObject1Collection= class (TObjectCollection) function GetMember: TObject1; ... ... public property Member [Index: Integer]: TObject1 read GetMember; ... procedure Add (ANewMember: TObject1); ... end; procedure TObject1Collection.Add (ANewMember: TObject1); begin (Self AS TObjectCollection).Add (ANewMember AS TObject); end; procedure TObject1Collection.GetMember: TObject1; begin Result:= (Self AS TObjectCollection).Member AS TObject1;end; 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.

For delphi you must use the 'overload' directive.

Michael.

Reply by email