[fpc-pascal] PASCAL programming for Novice
Leonardo M. Ram�
martinrame at yahoo.com
Sat Jun 9 17:10:48 CEST 2007
Francisco, that's not only a class, it's a Program containing the THelloWorld class.
With Object Pascal (and Pascal), you can divide your program in units, then use those units in a
program.
Example:
------------------------------------
Unit HelloWorld;
interface
type
THelloWorld = class
procedure Put;
end;
implementation
procedure THelloWorld.Put;
begin
WriteLn('Hello, World!');
end;
end.
------------------------------------
program MyProgram
uses
HelloWorld; // this includes HelloWorld into your program
var
myHelloWorl: THelloWorld; // to declare a variable of type THelloWorld
begin
myHelloWorld := THelloWorld.Create; // to create an instance of THelloWorld.
myHelloWorld.Put; // to execute Put method.
myHelloWorld.Free; // to destroy the instance.
end.
-----------------------
Leonardo M. Ramé
http://leonardorame.blogspot.com
--- Francisco Reyes <lists at stringsutils.com> wrote:
> Michael Van Canneyt writes:
>
> > Both Turbo Pascal's Object Pascal and Delphi's object pascal are
> > supported, depending on which mode you compile in.
>
> If I have a class like:
> program myclass;
> type
> THelloWorld = class
> procedure Put;
> end;
> var
> HelloWorld: THelloWorld;
> procedure THelloWorld.Put;
> begin
> WriteLn('Hello, World!');
> end;
> begin
> HelloWorld := THelloWorld.Create;
> HelloWorld.Put;
> HelloWorld.Free;
> end.
>
>
> How do I use that class in another program?
>
>
> _______________________________________________
> fpc-pascal maillist - fpc-pascal at lists.freepascal.org
> http://lists.freepascal.org/mailman/listinfo/fpc-pascal
>
____________________________________________________________________________________
Need a vacation? Get great deals
to amazing places on Yahoo! Travel.
http://travel.yahoo.com/
More information about the fpc-pascal
mailing list