Solved

How to create a TIniFile object

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

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

770 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