Var (keyword)
From RemObjects Software
var is used to define and optionally initialize a variable.
In classic Pascal and Delphi, var was actually a separate section in the beginning of a method.
While this still works in Oxygene, you can use var inline with your code.
Old style var section
method DoSomething; var someInt: Integer; someBoolean: Boolean; begin //some code end;
var as inline statement
method DoSomething; begin var someInt: Integer; //some code var someBoolean: Boolean; //some more code var AnswerToLifeTheUniverseAndEverything: Integer := 42; end;
the var keyword can also be used in combination with Type Inference
method DoSomething; begin var someInt := SomeMethodThatReturnsAnInteger(); //some code var someBoolean := SomeMethodThatReturnsABoolean(); //some more code end;
In the above code the two variables are still strongly typed, but there type is inferred from the method call return type.
Also var can be used to declare method parameters:
method Test1(a1: Word; var a2: Integer; var a4: Byte);
Changing value of this parameters will affect the caller.
See Also
Product: RemObjects Oxygene (formerly known as Chrome)
Current version: 3.0
Previous Versions: 'Joyride' (2.0), 'Floorshow' (1.5), 'Adrenochrome' (1.0)
Glossary — Keywords — Language Features — Platform Features — Samples — Articles — How To — Issues
Categories: Text | Oxygene | Language | Keyword
