What should the TIniFiles initial state be after defining in a procedure/function? Shouldn't the value assigned to a Tinifile be nil at the start?
What should the TIniFiles initial state be after defining in a procedure/function? Shouldn't the value assigned to a Tinifile be nil at the start?
When calling this example passing FALSE, the check for not assigned comes up true, yet it isn't. Now if I pass TRUE and manually initialize value to Nil, I'm ok.
This is Delphi 10 Seattle Update 1.
procedure IniWrite(NilFirst: boolean);
var
Ini1: tinifile;
begin
if NilFirst then
Ini1:= nil;
if not(assigned(Ini1)) then
Ini1 := TInifile.Create(IFILE);
try
Ini1.WriteString('xyz','a','TEST');
finally
Ini1.Free;
end;
end;
When calling this example passing FALSE, the check for not assigned comes up true, yet it isn't. Now if I pass TRUE and manually initialize value to Nil, I'm ok.
This is Delphi 10 Seattle Update 1.
procedure IniWrite(NilFirst: boolean);
var
Ini1: tinifile;
begin
if NilFirst then
Ini1:= nil;
if not(assigned(Ini1)) then
Ini1 := TInifile.Create(IFILE);
try
Ini1.WriteString('xyz','a','TEST');
finally
Ini1.Free;
end;
end;
Only managed types (like strings) are initialized, all other types including objects (in non-ARC) has unpredictable initial value.
ReplyDeletethe value of ini1 is undefined
ReplyDeleteprocedure IniWrite(NilFirst: boolean);
var
Ini1: tinifile;
begin
Ini1 := TInifile.Create(IFILE);
try
Ini1.WriteString('xyz','a','TEST');
finally
Ini1.Free;
end;
end;
That is as designed and documented http://docwiki.embarcadero.com/RADStudio/Seattle/en/Variables
ReplyDelete"On the Wiin32 platform, the contents of a local variable are undefined until a value is assigned to them."
This question is not specific to TIniFile. Try and ask it again for, say, Integer.
ReplyDeleteprocedure foo;
var
i: Integer;
begin
// what is the value of i at this point?
end;
http://docwiki.embarcadero.com/RADStudio/Seattle/en/Variables
ReplyDeleteOn the Wiin32 platform, the contents of a local variable are undefined until a value is assigned to them.