Consider this:
====
type
{ TRec }
TRec = record
// whatsoever
class operator Initialize(var aRec: TRec);
end;
{ TRec }
class operator TRec.Initialize(var aRec: TRec);
begin
writeln('class operator TRec.Initialize(var aRec: TRec)');
end;
function foo: TRec;
begin
writeln('foo');
end;
begin
foo;
end.
===
It outputs:
C:\Users\Bart\LazarusProjecten\ConsoleProjecten>test
class operator TRec.Initialize(var aRec: TRec)
foo
So, the initialization code is called before anything in the function.
Bart
On Sat, Nov 2, 2024 at 6:54 PM Thomas Kurz via fpc-pascal
<[email protected]> wrote:
>
> Hello,
>
> when I make a record type managed by adding an `Initialize` operator
> according to [1], can I rely on the record being initialized at the beginning
> of a function in which the record is the function result?
>
> Example:
>
> type TRec = record
> // whatsoever
> class operator Initialize(var aRec: TRec);
> end;
>
> function DoSomething: TRec;
> begin
> // <---- can I assume that `Result` is initialized when the function is
> entered?
> // more code
> end;
>
> [1] https://wiki.freepascal.org/management_operators
>
> _______________________________________________
> fpc-pascal maillist - [email protected]
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
--
Bart
_______________________________________________
fpc-pascal maillist - [email protected]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal