delphi - check if a inifile is existing or still <nil> in my code sequence -
the following code
var ainifile: tinifile; procedure aspecialevent (ainifile: tinifile ); begin .... if (ainifile <> nil) begin if fileexists(ainifile.filename) // error here .... begin ...... end; end; end; // mainformcode // need call procedure tini file not yet created aspecialevent(ainifile); fails access violation. infile not nil can not access the filename property. how check more efficient if file valid or not?
the explanation 1 of following:
ainifilehas not been initialised , has ill-defined value.ainifilehas been initialised, refers object has been destroyed.ainifilemember of record or class, , implicitselfpointer invalid. option seems rather unlikely.
it's impossible diagnose more that, 1 of above reason error.
judging comments, looks have not initialised local variable ainifile. in case item 1 applies. suspect expecting local variables automatically initialised. not case: are delphi variables initialized value default?
if wish nil mean object has not been instantiated, have explicitly initialise ainifile nil.
Comments
Post a Comment