For classes, the lifetime of an instance of a class is explicitly managed by the programmer. It is therefor clear what the Self parameter means and when it is valid.
Records and other simple types are allocated on the stack, which means they go out of scope when the function, procedure or method in which they are used, exits.
Combined with the fact that helper methods are type compatible to class methods, and can therefor be used as event handlers, this can lead to surprising situations: The data pointer in a helper method is set to the address of the variable.
Consider the following example:
This will print something like (the actual value for data may differ):
The variable i is still in scope when m is called.
But changing the code to
The output will be:
The actual output will depend on the architecture, but the point is that i is no longer in scope, making the output of it’s value meaningless, and possibly even leading to access violations and program crashes.