Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to create a TIniFile object

Posted on 1998-11-13
3
Medium Priority
?
273 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 150 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

705 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