This is because the record itself refers only to the data that makes up the record, and not to procedures or functions. Procedures and functions are a kind of syntactic sugar to avoid passing the record itself as a parameter: the self variable, which is automatically added by the compiler for you.
Each method that you declare in a record has a different parameter for the record itself, for example:
TData2 = record Age : Byte; Id : Integer; procedure Foo1; procedure Foo2(SomeParam: Integer); end;
changes to something equivalent to:
PData2 = ^TData2; TData2 = record Age : Byte; Id : Integer; end; procedure TData2_Foo1(Self: PData2); procedure TData2_Foo2(Self: PData2; SomeParam: Integer);
the end of each call you make also changes, for example:
var Data: TData2; begin Data.Foo1; Data.Foo2(1); end;
changes for something equivalent:
var Data: TData2; begin TData2_Foo1(@Data); TData2_Foo1(@Data, 1); end;
I don't have Delphi on hand to check if a parameter is added at the beginning or at the end of the parameter list, but I hope you get this idea.
Of course, there is no real syntax for this, since it is executed on the fly by the compiler, and thus, for example, the names of the procedures are not changed. I did this in an attempt to understand my answer.
jachguate
source share