Using INI Files/es

From Free Pascal wiki
Revision as of 23:14, 26 February 2011 by Iskraelectrica (talk | contribs) (New page: {{INI Files}} Category:CastellanoCategory:Español ==Archivos INI== ===Información Básica===    Los archivos INI se pueden utilizar para guardar la configurac...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

العربية (ar) Deutsch (de) English (en) español (es) suomi (fi) français (fr) polski (pl) русский (ru) 中文(中国大陆)‎ (zh_CN)

Archivos INI

Información Básica

   Los archivos INI se pueden utilizar para guardar la configuración básica del usuario con facilidad. Con la unidad INIfiles y la clase TINIFile puedes trabajar fácilmente con los archivos INI. Esta unidad forma parte de la FCL.

Estructura del archivo INIs

   Los archivos INI utilizan corchetes para incluir secciones. En estas secciones se encuentran las claves y los valores de las claves.

   La clave y su valor están separados mediante el símbolo (=) .

   Los nombres de sección se escriben entre corchetes ([UnaSeccion]). Los archivos INI no son tan populares como los archivos XML, debido a que no manejan muy bien grandes cadenas de texto.

Ejemplo

   Crearemos una sencilla aplicación de consola. Lo primero que hará es crear un archivo INI y llamado DB.ini y lo pondrá en el directorio de la aplicación. Contendrá una sección llamada INIDB, y las claves y valores siguientes:


Autor=Adam
Contrasenya=
ArchivoDB=Dinero.dat

   Veremos ahora el código:

<Delphi> Program Proyecto1;

{$mode objfpc}{$H+}
Uses
 Classes,SysUtils,INIFiles;
Var
 INI:TINIFile;
 Autor,Contrasenya,ArchivoDB:String;
 ContrasenyaIntroducida:String;
begin
 INI := TINIFile.Create('DB.ini');
 Author := INI.ReadString('INIDB','Autor',);
 Pass := INI.ReadString('INIDB','Pass',);
 DBFile := INI.ReadString('INIDB','DBFile',);
 if Pass <>  then
 begin
   Writeln('Password Required');
   Repeat
     Readln(PassEnter);
     if not PassEnter = Pass then Writeln('Wrong Password');
   until(PassEnter = Pass);
   Writeln('Correct Password');
 end;
 Writeln('Author : '+Author);
 Writeln('File : '+DBFile);
 Writeln('Password : '+Pass);
 Readln;
end.</Delphi>

Objetos a conocer

In the TINIFile class there are many different Propertys, procedures and functions to be used.

CaseSensitive - This property allows you to say if the keys and sections are case sensitive or not.. by default they aren't..

ReadString - Has 3 constant statements. the first one is the section to search in. The second one is the key to look for. The third one is a default string incase the key and\or section searched for is not found.

WriteString has three constant statements too... The first is the section. The second is the key and the last is the Value. If the key and section exist already the Key will be over written with the new value..

ReadSections - Will allow you to to take the sections from the INI file and put them in a TStrings class(Or TStringList with the AS code)

DeleteKey - Remove an existing Key from a specific section

EraseSection Remove a section and all its data

There are more procedures and functions but this is basic..

Last words...

Here: [1] you can learn all about INI Files to.. Please, if you can put up more information about INI files in Pascal. Modify At Will

Ver también