[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

access violation when writing ini file

Posted on 2004-08-08
4
Medium Priority
?
351 Views
Last Modified: 2010-04-05
I have been working on this for most of the day.  its driving me nuts.    I have a series of textfields that are filled in from an ini file.    Here is all relevent code:

to read the information

procedure TForm1.Settings2Click(Sender: TObject);
begin
settingsini := TIniFile.Create('.\settings.ini');
       try

       ftphost := settingsini.readstring('Server Settings','host', 'none' );
       ftpusername := settingsini.readstring('Server Settings','username', 'none');
       ftppassword := settingsini.readstring('Server Settings','password', 'none');
       ftppath := settingsini.readstring('Server Settings','path', 'none');

       frmsettings.txtFtpHost.text := ftphost;
       frmsettings.txtFtpusername.text := ftpusername;
       frmsettings.txtFtppassword.text := ftppassword;
       frmsettings.txtFtpPath.text := ftppath;
       except
      showmessage('Settings.ini - problem reading inifile');
       end;                                                            
       free;




frmsettings.Show;
end;







to write it back to file when "save" button is clicked

procedure Tfrmsettings.PDJXPButton1Click(Sender: TObject);
begin

settingsini := TIniFile.Create('.\settings.ini');
  with settingsini do
      begin
    try
          writestring('Server Settings','host', frmsettings.txtFtpHost.text);
          writestring('Server Settings','username', frmsettings.txtFtpusername.text);
          writestring('Server Settings','password', frmsettings.txtFtppassword.text);
          writestring('Server Settings','path', frmsettings.txtFtpPath.text);
     except
     showmessage('there was a problem writing the file');
     end;
        free;
      end;
      frmsettings.hide;
end;



/////////////////////////////////////end code

I have no problem READING the file.  When I try to WRITE the file again I run into an access violation.   I dont know why this happens.   I have tried a number of things many of them obviously incorrect even to me but still have not had luck.  I tried removing the second tinifile.create (the writing one) based on the idea that it had already been done.  This neither fixed the problem nor made it worse.

Anyone have any ideas? I'm always on a deadline but this one is rather worse than usual.




0
Comment
Question by:hibbidiji
  • 2
4 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 1200 total points
ID: 11748872
It would be helpful, if you know it, to reveal at what point the error pops up? (which line is the culprit?)

I tried your code, and it worked fine here. The only change I made was:
 
in settings2clisk, change the Free to settingsini.free

I didn't try the creating the input fields, but I doubt if that's where the error lies.
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11748889
I tried it again, and making it settingsini.free in settings2click should fix it. I put it back the way you had it, and forced it to read, then call the write routine, and I got your error message.

Hope that helps!
0
 
LVL 17

Assisted Solution

by:Wim ten Brink
Wim ten Brink earned 800 total points
ID: 11749055
What you're doing is basically plain stupid.

Sorry but lines like:
* writestring('Server Settings','host', frmsettings.txtFtpHost.text);
Just don't make sense if you define them in a class named Tfrmsettings. Chances are that the form just doesn't even know the right value for frmsettings. Try using
* writestring('Server Settings','host', txtFtpHost.text);
instead... The difference is that at the moment you call PDJXPButton1Click, the variable frmsettings is probably unassigned. If not, the value frmsettings might be pointing at the wrong form. And that's what creates your access violation...

Just an example of erroneous copying&pasting code, I guess. :-)
0
 
LVL 1

Author Comment

by:hibbidiji
ID: 11750029
The program was crashing because of both problems.   I gave the extra 100 to the first answer on the buzzer :)   Thanks guys and alex, dont apologize for my MISERABLE coding. I'm a php guy and new to delphi.  Its just my inexperiance talking...  :)
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month19 days, 14 hours left to enroll

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question