Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

access violation when writing ini file

Posted on 2004-08-08
4
Medium Priority
?
345 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
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…
Suggested Courses

610 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