Solved

How to create a TIniFile object

Posted on 1998-11-13
3
262 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
Comment Utility
Begin
   Archivo=TIniFile.Create('Monitor.ini');
   with Archivo do
   begin
      Puerto:=...
      ....
   end;
   Archivo.Free;  
end;
0
 
LVL 1

Expert Comment

by:sassas081597
Comment Utility
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
Comment Utility
or you could simply do this...

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

Cheers,
Viktor
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Delphi XE7 Rest Client 2 172
Delphi TcxGrid group footer summary 3 143
oracle global variables 4 51
creating threads in delphi 1 52
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now