Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Object Pascal
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
====Heap based allocation==== <syntaxhighlight lang="objectpascal"> program ObjectPascalExample; type PHelloWorld = ^THelloWorld; THelloWorld = object procedure Put; end; procedure THelloWorld.Put; begin WriteLn('Hello, World!'); end; var HelloWorld: PHelloWorld; { this is a typed pointer to a THelloWorld } begin New(HelloWorld); HelloWorld^.Put; Dispose(HelloWorld); end. </syntaxhighlight> Another example: <syntaxhighlight lang="objectpascal"> program ObjectPascalExample; type PHelloWorld = ^THelloWorld; THelloWorld = object procedure Put; end; procedure THelloWorld.Put; begin WriteLn('Hello, World!'); end; var HelloWorld: PHelloWorld; { this is a typed pointer to a THelloWorld } HelloWorld2: ^THelloWorld; { this is exactly the same with different syntax } HelloWorld3: ^THelloWorld; HelloWorld4: PHelloWorld; begin { This works in a similar way as the code above, note the allocation and de-allocation, though, many people get confused. In the past there was a wrong example with wrong comments here... } New(HelloWorld); { one instance } HelloWorld4 := HelloWorld; { this is valid - a pointer copy } HelloWorld2 := HelloWorld; { this is valid - a pointer copy } New(HelloWorld3); { a second instance } HelloWorld4 := HelloWorld3; { this is valid - a pointer copy } HelloWorld2 := HelloWorld3; { this is valid - a pointer copy } Dispose(HelloWorld); { it allocates only two instances } Dispose(HelloWorld3); { so it must release only two instances } end. </syntaxhighlight> This works based on pointer copy, unless there is a specific allocation for a deeper copy.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)