Solved

How to create a TIniFile object

Posted on 1998-11-13
3
271 Views
Last Modified: 2010-04-04
Hi.... I'm trying to use a INI file in my program, but I don't know how to initialize it... I have the following procedure that plans to read a file called Monitor.ini:

procedure SetSerial;
var
  Archivo   : TIniFile;
  Puerto    : Byte;
  Baudios   : Integer;
begin
  with Archivo do
    begin
      Create('Monitor.ini');
      Puerto   := ReadInteger('Setup','Puerto',2);
      Baudios  := ReadInteger('Setup','Baud',19200);
      Archivo.Free;
      Emulador.Serial.DeviceName := 'Com' + Chr(Puerto+$30);
      case Baudios of
        2400  : Emulador.Serial.BaudRate := br2400;
        4800  : Emulador.Serial.BaudRate := br4800;
        9600  : Emulador.Serial.BaudRate := br9600;
        19200 : Emulador.Serial.BaudRate := br19200;
      end;
    end;
end;

When I compile it, compiler says the error that Archivo variable might not be initialized. What can I do before calling the Create method in order to initialize the object?

Thank in advance
Jaime
0
Comment
Question by:skel
[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
3 Comments
 
LVL 1

Accepted Solution

by:
sassas081597 earned 50 total points
ID: 1346763
Begin
   Archivo=TIniFile.Create('Monitor.ini');
   with Archivo do
   begin
      Puerto:=...
      ....
   end;
   Archivo.Free;  
end;
0
 
LVL 1

Expert Comment

by:sassas081597
ID: 1346764
Comment to the answer: You should to use the class method TIniFile.Create(...), not the pointer's method Archivo.Create(...).
0
 
LVL 10

Expert Comment

by:viktornet
ID: 1346765
or you could simply do this...

with TIniFile.Create do
try
  //Code....
finally
  Free;
end;

Cheers,
Viktor
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

623 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