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

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


> Basically, the 
> first step towards objects is ENCAPSULATION, which is PURE 
> SYTNAX, i. e. there are no constructors / destructors required. 

An Object is an Instance of a Class. A class needs to be constructed.
Even C++ stack based instances have a constructor. What you want is for
the constructor to be implicetly called. This is something quite
different.

The Turbo Pascal style is very outdated.

> Your example, including a procedure "main" actually using the object
would then be:

I would like to see the removal of the distiction between procedure and
function. This would be replaced by a generic 'method'. I would like to
see static methods, as in C++, that can be used as if they were external
procedures or functions, but are logically bound to the class. This
would make things like WindProcs and WinAPI call backs much cleaner. I
would like to see a Java like mode, with no external items, everything
is part of a class. I would like to see namespaces, and therefore easier
scope resolution that just relying on the unit name (maybe a bit like
packages in ADA??) No more Units. Separate Interface and implementation
files. Inline code!

Maybe I should just wait for Delphi.NET ;-) that will be at least part
of the way there!


// file : MyPascalModification.Int[erface]

Interface MyPascalModification;

Namespace MattsStuff;

Type
  MyWin = class(Windows.Forms.Window);

  MyApp = class(Windows.Application.WinApplication)
    static method WinProcWindow: HWND; Message, WParam: Longint; LParam:
Longint): Longint; stdcall;
    static method Main(cmdline: Tstrings): void; inline;
    begin
      app := MyApp.Create(...);
      try
        app.MainWindow := MyWin.Create(...);
        app.Run();
      finally
        app.free;
      end;
    end;
    method Test: void;
    
  end;
End.

// file : MyPascalModification.imp[lementation]

Implementation MyPascalModification;

Interfaces MyPascalModification; //overkill??

Using namespace MattsStuff;

method MyApp.Test: void;
Begin
  Console.writeln('test');
End;

static method MyApp.WinProcWindow: HWND; Message, WParam: Longint;
LParam: Longint): Longint; stdcall;
Begin
  ...
End;

End.

  




More information about the fpc-pascal mailing list