TRSE
TRSE copied to clipboard
Unexpected Local Variable behaviour in Class Procedures
Classes own variables are "local" to the class, but procedures inside the class share local variables with each other and the global space.
The reason why is logical when explained, but illogical in the context of classes where a seemingly "global" parameter defined with the class, is unique to the object, but variables defined just below in a procedure, isn't. Example:
var // global definitions
x,y:byte
Person_Draw_y_precalc:integer;
var
Person = class // we now enter "Class space"
x,y:byte; // Unique and allowed - not already defined
procedure DrawSmall();
var
Person_Draw_y_precalc:integer; // compile error - already defined
begin
This can probably be solved by turning on local variables in the settings.
Suggestion: turn local variables ON by default in classes - or turn it on by default in entire TRSE. After all if global variables are / wanted needed - the coder can just remove the ones in question from the procedures local variable definition - or move them "out" of the procedure definition - and they would be global.