Sign in Join

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

Mailing lists / fpc-pascal / 2003-02

RE: Classes/Objects/Pointers / Pointer Help

1 message · 1 person ·

Reply by email Subscribe to this list Your subscription

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

Matt Emson

This is where Classes are better than objects... This will only work if you don't reference any thing that is instantiated by the constructor, i.e. all Methods and fields.

*** type TmyObject = object procedure test; end;
type
  TMyClass = class
    class procedure test;
  end;
procedure TmyObject.test; begin    writeLn('test'); end;

As is, but add 'class' prefix..

Show quoted text 7 lines
procedure main; var MyObject: TmyObject; begin MyObject.Test; end; ***

No changes.

What you want is garbage collection, not a lack of constructors/destructors... What you will get is VBPascal. Nasty.

You could try:

  IMyClass = interface
    procedure Test;
  end;
  TMyClass = class(TInterfacedObject, IMyClass)
    class function Get(): TMyClass;
    procedure Test;
  end;
Class function TMyClass.Get() : IMyClass;
Begin
  result := TMyClass.Create;
End;

Though this is quite nasty in itself too.

Matt