3 ms·
Delphi does default initialize global variables and member variables of objects. It doesn't default initialize local variables (but it should for consistency).
by zfg 2y ago
Delphi does default initialize global variables and member variables of objects. It doesn't default initialize local variables (but it should for consistency).
Inline variable declaration with initialization makes it a bit nicer. You can write:
var myVar := 25;
To initialize myVar and type inference will make it an Integer. You can specify type if needed:
var myVar : Integer := 25;
In their examples they say:
ShowMessage('obj2.n2: ' + IntToStr(obj2.n2)); // Shows 0 - uninitialized memory
But actually n2 is initialized to zero.
And in the example freeing of objects, instead of using:
obj1.Free;
They should always use:
FreeAndNil(obj1);
That will free the object and set the object pointer to nil. Any subsequent attempt to access obj1 will result in an access violation.