Lazarus
Home
Help
TinyPortal
Search
Login
Register
Lazarus
»
Forum
»
Programming
»
General
»
Playing around with properties
Free Pascal
Website
Downloads
Wiki
Documentation
Bugtracker
Mailing List
Lazarus
Website
Downloads (Laz+FPC)
Packages (OPM)
FAQ
Wiki
Documentation (RTL/FCL/LCL)
Bugtracker
CCR Bugs
GIT
Mailing List
Other languages
Foundation
Website
Useful Wiki Links
Project Roadmap
Getting the Source
Screenshots
How to use the forum
Forum Rules
About donations (wiki)
Bookstore
Computer Math and Games in Pascal
(preview)
Lazarus Handbook
Search
Advanced search
Recent
I hope FreePascal can sup...
by
Khrys
[
Today
at 09:39:20 am]
How to merge multiple cla...
by
cdbc
[
Today
at 09:39:16 am]
Little bit...
by
egsuh
[
Today
at 09:37:52 am]
Remote desktop software i...
by
Ericktux
[
Today
at 08:50:58 am]
Fixed Bzip2 unpacker from...
by
domasz
[
Today
at 08:09:54 am]
Ann: DeCoperators
by
Thaddy
[
Today
at 07:37:29 am]
Strange happenings with T...
by
mas steindorff
[
Today
at 03:58:33 am]
Weird error
by
xiyi0616
[
Today
at 03:47:04 am]
Can't pass string to TEdi...
by
mas steindorff
[
Today
at 03:45:21 am]
AI assisted translation o...
by
MathMan
[April 12, 2026, 11:48:54 pm]
Bad Sandwich
by
Guva
[April 12, 2026, 09:55:25 pm]
FPC Unleashed (inline var...
by
440bx
[April 12, 2026, 09:38:20 pm]
ZeosDB and sqlite3
by
dseligo
[April 12, 2026, 09:06:22 pm]
The ever re-appearing /= ...
by
Thaddy
[April 12, 2026, 08:07:09 pm]
Some Lazarus Graphics Rel...
by
Boleeman
[April 12, 2026, 03:45:30 pm]
Some Lazarus Utils N Stuf...
by
Boleeman
[April 12, 2026, 03:39:45 pm]
Ann: Deinline: a de-inlin...
by
Fred vS
[April 12, 2026, 03:17:40 pm]
BAScript - Simple scripti...
by
Ñuño_Martínez
[April 12, 2026, 01:00:21 pm]
NiceGrid component for La...
by
Alexandr R
[April 12, 2026, 11:02:54 am]
Idea to solve a circular ...
by
jamie
[April 12, 2026, 10:55:07 am]
Status of Fresnel Project...
by
Thaddy
[April 12, 2026, 08:47:30 am]
Help with OLD code
by
Thaddy
[April 12, 2026, 08:17:11 am]
Can /my/ AI help me with ...
by
MathMan
[April 12, 2026, 07:33:14 am]
Lazarus Image Editor
by
Boleeman
[April 12, 2026, 03:46:20 am]
Splitting Picture into Qu...
by
Boleeman
[April 12, 2026, 02:43:50 am]
« previous
next »
Print
Pages: [
1
]
Author
Topic: Playing around with properties (Read 398 times)
JdeHaan
Full Member
Posts: 171
Playing around with properties
«
on:
May 02, 2025, 11:43:57 am »
This is not a question. I just wanted to share this code, of which I wasn't aware that this was possible in FP. Especially, the way the record is created/initialized, using a property instead of a constructor.
Code: Pascal
[Select]
[+]
[-]
program
Project1
;
{$Mode Delphi}
type
TTimesTable
=
record
private
fMultiplier
:
Integer
;
function
Init
(
Multiplier
:
Integer
)
:
TTimesTable
;
function
Multiply
(
Value
:
Integer
)
:
Integer
;
public
property
Multiplier
:
Integer
read
fMultiplier
;
property
Create
[
Multiplier
:
Integer
]
:
TTimesTable
read
Init
;
property
Item
[
Value
:
Integer
]
:
Integer
read
Multiply
;
default
;
end
;
{ TTimesTable }
function
TTimesTable
.
Multiply
(
Value
:
Integer
)
:
Integer
;
begin
Result
:
=
Value
*
fMultiplier
;
end
;
function
TTimesTable
.
Init
(
Multiplier
:
Integer
)
:
TTimesTable
;
begin
fMultiplier
:
=
Multiplier
;
Result
:
=
Self
;
end
;
var
Table
:
TTimesTable
;
n
:
Integer
;
begin
Table
.
Create
[
7
]
;
WriteLn
(
'Table of '
,
Table
.
Multiplier
,
':'
)
;
for
n
:
=
1
to
10
do
WriteLn
(
n
:
2
,
' x '
,
Table
.
Multiplier
,
' = '
,
Table
[
n
]
:
2
)
;
end
.
Logged
Thaddy
Hero Member
Posts: 18943
Glad to be alive.
Re: Playing around with properties
«
Reply #1 on:
May 02, 2025, 12:13:17 pm »
Two remarks:
1. It is a record
2. A property can be named as - almost - anything, you just happened to call it create.
But yes, this is completely legal code.
«
Last Edit: May 02, 2025, 12:17:00 pm by Thaddy
»
Logged
Recovered from removal of tumor in tongue following tongue reconstruction with a part from my leg.
Print
Pages: [
1
]
« previous
next »
Lazarus
»
Forum
»
Programming
»
General
»
Playing around with properties
TinyPortal
© 2005-2018