Solved

How to create a TIniFile object

Posted on 1998-11-13
3
270 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

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

Suggested Solutions

Title # Comments Views Activity
JAudiorecorder record freezing the app 29 92
How to create virtual printer while installing my application 5 84
update joined tables 2 74
DBCtrlGrid, Delphi, Scroll 8 87
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

751 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