[fpc-pascal]Classes/Objects/Pointers / Pointer Help

Matt D. Emson matt at Diplomat.co.uk
Mon Feb 10 14:30:06 CET 2003

-----Original Message-----
From: Matt Emson [mailto:memsom at interalpha.co.uk] 
Sent: 10 February 2003 13:29
To: 'fpc-pascal at deadlock.et.tudelft.nl'
Subject: RE: [fpc-pascal]Classes/Objects/Pointers / Pointer Help

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;

  TMyClass = class
    class procedure test;
> procedure TmyObject.test;
> begin
>    writeLn('test');
> end;

As is, but add 'class' prefix..
> 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;

  TMyClass = class(TInterfacedObject, IMyClass)
    class function Get(): TMyClass;
    procedure Test;

Class function TMyClass.Get() : IMyClass;
  result := TMyClass.Create;

Though this is quite nasty in itself too.


More information about the fpc-pascal mailing list