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:

  1. ainifile has not been initialised , has ill-defined value.
  2. ainifile has been initialised, refers object has been destroyed.
  3. ainifile member of record or class, , implicit self pointer 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

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -