Object Pascal: Difference between revisions

Content deleted Content added
m add PascalABC to infobox dialects
"Modern Pascal" is not modern Pascal, but a non-notable dialect that’s irrelevant in the context of this article
Tag: section blanking
Line 267:
</syntaxhighlight>
Note that the object construct is still available in Delphi and Free Pascal.
 
===Modern Pascal version===
<syntaxhighlight lang="delphi">
program ObjectPascalExample;
 
type
THelloWorld = class
Put:procedure of object;
end;
 
procedure THelloWorld.Put;
begin
Writeln('Hello, World!');
end;
 
procedure THelloWorld.Free;
begin
// dispose any pointers //
end;
 
procedure THelloWorld.Init;
begin
// initialize variables
// link methods (manual RTTI)
with Self do begin
TMethod(@Put):=[@THelloWorld.Put, @Self];
TMethod(@Free):=[@THelloWorld.Free, @Self];
End;
end;
 
var
HelloWorld: THelloWorld; { this is an implicit pointer }
 
begin
HelloWorld.Init; { self initialization (pointer to an object) of type THelloWorld }
HelloWorld.Put;
HelloWorld.Free; { this line deallocates the THelloWorld object pointed to by HelloWorld }
end.
</syntaxhighlight>
 
===Oxygene version===