Solved

.ini file

Posted on 2000-03-19
1
276 Views
Last Modified: 2010-04-04
In my application, there are two report forms. when closing each report form, the report form write the left, top, height, width into .Ini file, so next time the report will show on position as  that on last time.
When I click a button and produce a report A and close it, then click another button to generate another report B, and close it, thare are no problem.
When I produce report A and than report B, then close A( or B), it is still fine, but when I then close B(or A), I got the TExternalException message.
I find when write the form.left into the .ini file, the error message occurs.

The following is the procedure that write the .ini file

procedure WriteIni(formname : TForm);
var status : integer;
    Ininame: string;
begin
  Status := 1;
  if not assigned(SptIni) then
  begin
    Ininame := ExtractFilePath(ParamStr(0)) + 'fSptIni.ini';
    SptIni := TIniFile.Create(Ininame);
  end;

  with SptIni do begin
    case formname.WindowState of
      wsNormal: begin
          WriteInteger('Support', 'Left', formname.Left);
          WriteInteger('Support', 'Top', formname.Top);
          WriteInteger('Support', 'Width', formname.Width);
          WriteInteger('Support', 'Height', formname.Height);
        end;
      wsMiniMized:
          Status := 2;
      wsMaximized:
          Status := 3;
    end;//case
  if not formname.Active then
    Status := 2;
    {write status information}
  SptIni.WriteInteger ('Support', 'Status', Status);
  {destroy the IniFile object}
  SptIni.Destroy;
  end;
end;


Best regards

PeterShaw
 
0
Comment
Question by:petershaw9
[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
1 Comment
 
LVL 12

Accepted Solution

by:
rwilson032697 earned 50 total points
ID: 2634242
Try writing the procedure like this, with the INI file obkect locally:

procedure WriteIni(formname : TForm);
var status : integer;
    Ininame: string;
    SptIni : TIniFile;
begin
  Status := 1;
  Ininame := ExtractFilePath(ParamStr(0)) + 'fSptIni.ini';
  SptIni := TIniFile.Create(Ininame);

  with SptIni do begin
    case formname.WindowState of
      wsNormal: begin
          WriteInteger('Support', 'Left', formname.Left);
          WriteInteger('Support', 'Top', formname.Top);
          WriteInteger('Support', 'Width', formname.Width);
          WriteInteger('Support', 'Height', formname.Height);
        end;
      wsMiniMized:
          Status := 2;
      wsMaximized:
          Status := 3;
    end;//case
  if not formname.Active then
    Status := 2;
    {write status information}
  SptIni.WriteInteger ('Support', 'Status', Status);
  {destroy the IniFile object}
  SptIni.Free;
  end;
end;

Cheers,

Raymond.

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
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…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

631 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