Difference between revisions of "Using INI Files/ru"

From Lazarus wiki
Jump to navigationJump to search
Line 7: Line 7:
  
 
===Краткий состав===
 
===Краткий состав===
INI-файлы работают с секциями(Sections), ключами(Keys) и значениями(Values). Пример:<br>
+
INI-файлы работают с секциями(Sections), ключами(Keys) и значениями(Values).  
 +
Пример:<br>
 
[Section]<br>
 
[Section]<br>
 
Key=Value
 
Key=Value

Revision as of 12:07, 3 February 2012

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

Файлы INI

Обзор

INI-файлы могут быть использованы для сохранения пользовательских параметров. С модулем INIFiles и классом TINIFile вы можете легко работать с существующими INI файлами. Я покажу вам основы рабооты с классом TINIFile.

Краткий состав

INI-файлы работают с секциями(Sections), ключами(Keys) и значениями(Values). Пример:
[Section]
Key=Value

В одной секции может быть несколько ключей. В файле может быть несколько секций.


Для чего это нужно

INI-файлы позволяют очень просто читать и записывать данные. Как и XML-файлы.

Пример

So first things first.. Lets do a basic console application. <Delphi> Progam INIex;

{$mode objfpc}

Uses

SysUtils,INIFiles;{INIFiles = The unit with the INI Classes}

Var

IniF:TINIFile;//The class

</Delphi>

Something you have to know is that when using the TINIfile class you have to work with an existing INI file.. So open Note pad and create an INI file.. Lets use this as an example:

[S1]

Key1=Hello World

[S2]

Key2=Worldly Hello

Ok.. Now back to our code <Delphi> begin

 Writeln('Creating class');
 IF(FileExists('someini.ini'))then
 begin
   Inif := TINIFile.Create('someini.ini');
   Writeln(INiF.ReadString('s1','Key1',);
 End else Writeln('File not found...');
 Readln;

end. </Delphi>

Свойства и методы

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 third 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..

Заключение...

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