var parameter



Pass as Var-parameter
Smart pascal source code
type Toto = Class(TObject) public s: String; i: Integer; f: Float; b: Boolean; o: TObject; end; var obj: Toto; procedure tataS(var chaine: String); begin chaine := 'tata'; end; procedure tataI(var int: Integer); begin int := 456; end; procedure tataF(var fl: Float); begin fl := 4.5; end; procedure tataB(var b: Boolean); begin b := True; end; procedure tataO(var o: TObject); begin o := nil; end; {------ main.pas ------} Begin obj := Toto.Create; obj.s := 'toto'; obj.i := 123; obj.f := 1.5; obj.o := obj; WriteLn(obj.s); { <<< CONSOLE OUTPUTS >>> toto } /* tataS(obj.s); // Syntax Error: Only a variable can be be passed as Var-parameter tataI(obj.i); // Syntax Error: Only a variable can be be passed as Var-parameter tataF(obj.f); // Syntax Error: Only a variable can be be passed as Var-parameter tataB(obj.b); // Syntax Error: Only a variable can be be passed as Var-parameter tataO(obj.o); // Syntax Error: Only a variable can be be passed as Var-parameter */ WriteLn(obj.s); WriteLn(obj.i); WriteLn(obj.f); WriteLn(obj.b); if obj.o <> nil then WriteLn('bug'); { <<< CONSOLE OUTPUTS >>> toto 123 1.5 false bug }