I have a class
type
TLoadOption = class
private
FAutoSearch: Boolean;
public
property AutoSearch: Boolean read FAutoSearch write FAutoSearch;
end;
In one of the functions i am creating the object of the class in stack
procedure MyView.InitializeForm(const aMsg: MyMsg);
//---------------------------------------------------------------------------
var
Options: TLoadOption;
begin
if aMsg.OptionalObject <> nil then
Options := aMsg.OptionalObject as TLoadOption;
if Assigned(Options) and Options.AutoSearch then
DoRefresh;
end;
I am not passing anything in aMsg so ideally Options is not set.
In Delphi XE by default Options is set as nil and so this DoRefresh is not called but when i execute the same code in Delpi XE4 the options is initialized with some random value and AutoSearch becomes true always and it results in calling this DoRefresh function which is undesired.
I am wondering if there are any compiler options that set default values to uninitialized variable. My only solution as of now is like this
procedure MyView.InitializeForm(const aMsg: MyMsg);
//---------------------------------------------------------------------------
var
Options: TLoadOption;
begin
Options := nil;
if aMsg.OptionalObject <> nil then
Options := aMsg.OptionalObject as TLoadOption;
if Assigned(Options) and Options.AutoSearch then
DoRefresh;
end;
is this a correct way?