Difference between revisions of "Using INI Files/ar"

From Free Pascal wiki
Jump to navigationJump to search
(Created page with "<div dir="rtl"> ==ملفات اﻷعدادات INI== ===معلومات أساسية=== تستخدم ملفات INI لحفظ إعدادات المستخدم اﻷساسية ...")
 
m (Fixed syntax highlighting; deleted category included in page template)
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 +
{{INI Files}}
 +
 
<div dir="rtl">
 
<div dir="rtl">
 
==ملفات اﻷعدادات INI==
 
==ملفات اﻷعدادات INI==
Line 5: Line 7:
 
تستخدم ملفات INI لحفظ إعدادات المستخدم  اﻷساسية بسهولة , فعن طريق الوحدة  '''INIfiles''' و الفئة  '''TINIFile''' يمكنك بكل سهولة التعامل مع ملفات INI الموجودة مسبقا , تجد هذه الوحدة ضمن مكتبات  FCL
 
تستخدم ملفات INI لحفظ إعدادات المستخدم  اﻷساسية بسهولة , فعن طريق الوحدة  '''INIfiles''' و الفئة  '''TINIFile''' يمكنك بكل سهولة التعامل مع ملفات INI الموجودة مسبقا , تجد هذه الوحدة ضمن مكتبات  FCL
  
===INI Files===
+
===ملفات  INI===
INI Files use brackets to create and mark '''Sections''', which contain '''keys''' and key '''values'''.
+
تستخدم ملفات INI الأقواس لتحديد  '''اﻷقسام''' واللتي بدورها تحتوي علي  '''مفاتيح''' و '''قيم''' .
A Key and its corresponding Value are separated with an equals sign (Key=Value).
+
 
Section names are put inside square brackets ([Section]).
+
يتم الفصل بين المفتاح والقيمة المقابلة له بعلامة التساوي  (المفتاح=القيمة).
Comments are usually permitted and are marked with a semicolon (;) at the beginning of a line. As INI files are not totally standardized, other characters are also used, such as #
+
 
Nowadays, INI Files are used less than XML files for string storage, because INI files don't handle large strings very well.
+
أسماء اﻷقسام تكتب بين قوسين مربعين  ج[قسم].
 +
 
 +
التعليقات دائما مسموح بها ويسبق سطر التعليق  بعلامة الفاصلة المنقوطة  (;) ,وبماأن ملفات INI ليست قياسية بشكل كامل فأنه يمكن استخدام رموز التعليق اﻷخري كعلامة # .
 +
 
 +
حاليا يتم أستخدام ملفات INI أقل من أستخدام  ملفات xml لتخزين السلاسل النصية , لأن ملفات INI لا تستطيع معالجة النصوص الكبيرة بشكل جيد.
 +
 
  
An example ini file:
+
مثال علي ملف INI :
  
 
<syntaxhighlight lang="ini">
 
<syntaxhighlight lang="ini">
Line 30: Line 37:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Ini file reading example===
+
=== مثال قراءة ملف INI ===  
 
+
التطبيق التالي يوضح كيفية قراءة ملف INI , عليك أولا إنشاء ملف INI  واحفظه باسم "C:\DB.ini" .
The console application below shows how to read ini files. To test it one should create the following ini file with the name "C:\DB.ini". Edit it to so it contains a section called INIDB and the following keys and values:
+
أنشئ فيه قسم  باسم  INIDB واضف إليه المفاتيح والقيم التالية :
  
 
<syntaxhighlight lang="ini">
 
<syntaxhighlight lang="ini">
Line 42: Line 49:
 
</syntaxhighlight>
 
</syntaxhighlight>
 
   
 
   
Now let's move on the the code..
+
واﻵن لننتقل إلي الكود  ..
<syntaxhighlight>
+
 
 +
<syntaxhighlight lang=pascal>
 
Program IniSample;
 
Program IniSample;
  
Line 84: Line 92:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
===Objects to know===
+
===أشياء لابد أن تعرفها===
In the TINIFile class there are many different properties, procedures and functions that can be used.
+
تحتوي الفئة  TINIFile علي كثير من الخصائص واﻷجراءات والدوال اللتي يمكن استخدامها .
 +
 
 +
'''CaseSensitive''' - تتيح لك هذه الخاصية أن تجعل المفاتيح واﻷقسام حساسة لحالة اﻷحرف أم لا , افتراضيا غير حساسة لحالة اﻷحرف.
 +
 
  
'''CaseSensitive''' - This property allows you to say if the keys and sections are case sensitive or not. By default they aren't.
+
'''ReadString''' - تأخذ 3 مدخلات , اﻷول هو القسم اللذي يجب البحث فيه والثاني هو المفتاح اللذي سيتم البحث عنه والثالث هو قيمة افتراضية  حال أن القسم و/أو المفتاح المطلوبين غير موجودين
  
'''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 in case 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 that you want to write. If the key and section exist already, the key will be overwritten with the new value..
+
'''WriteString''' - تأخذ 3 مدخلات أيضا , اﻷول هو القسم والثاني المفتاح والثالث هو القيمة المراد اسنادها لهذا المفتاح , لاحظ أنه إذا كان المفتاح والقسم موجودين من قبل فأنه سيتم كتابة القيمة الجديدة فوق القديمة .  
  
'''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 operator).
+
'''ReadSections''' - تسمح لك بأخذ جميع اﻷقسام من ملف INI في صورة  TString  أو TStringList عن طريق  المعامل  As .  
  
'''DeleteKey''' - Remove an existing key from a specific section.
+
'''DeleteKey''' - تمكنك من حذف مفتاح موجود داخل أحد اﻷقسام .
  
'''EraseSection''' - Remove a section and all its data.
+
'''EraseSection''' - تمكنك من حذف قسم كامل بكل محتوياته .
  
There are more procedures and functions but this is enough to get you started.
 
  
===Reference Documentation===
+
وغير ذلك يوجد الكثير من اﻷجراءات والدوال ولكن ماسبق يكفي لكي تبدأ .
Here: [http://lazarus-ccr.sourceforge.net/docs/fcl/inifiles/index.html Free Pascal documentation on INI files]
 
  
 +
===المراجع===
 +
هنا: [http://lazarus-ccr.sourceforge.net/docs/fcl/inifiles/index.html Free Pascal documentation on INI files]
  
  
 +
== شاهد أيضا ==
  
 +
* [[XML Tutorial]]
  
 
</div>
 
</div>

Latest revision as of 09:06, 4 March 2020

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

ملفات اﻷعدادات INI

معلومات أساسية

تستخدم ملفات INI لحفظ إعدادات المستخدم اﻷساسية بسهولة , فعن طريق الوحدة INIfiles و الفئة TINIFile يمكنك بكل سهولة التعامل مع ملفات INI الموجودة مسبقا , تجد هذه الوحدة ضمن مكتبات FCL

ملفات INI

تستخدم ملفات INI الأقواس لتحديد اﻷقسام واللتي بدورها تحتوي علي مفاتيح و قيم .

يتم الفصل بين المفتاح والقيمة المقابلة له بعلامة التساوي (المفتاح=القيمة).

أسماء اﻷقسام تكتب بين قوسين مربعين ج[قسم].

التعليقات دائما مسموح بها ويسبق سطر التعليق بعلامة الفاصلة المنقوطة (;) ,وبماأن ملفات INI ليست قياسية بشكل كامل فأنه يمكن استخدام رموز التعليق اﻷخري كعلامة # .

حاليا يتم أستخدام ملفات INI أقل من أستخدام ملفات xml لتخزين السلاسل النصية , لأن ملفات INI لا تستطيع معالجة النصوص الكبيرة بشكل جيد.


مثال علي ملف INI :

; Comment. Beginning of INI file

; empty lines are ignored

; note that no section has been defined.
Compiler=Delphi
; Key: Compiler
; Value: Delphi

[General]
; This starts a General section
Compiler=FreePascal
; Key Compiler and value FreePascal

مثال قراءة ملف INI

التطبيق التالي يوضح كيفية قراءة ملف INI , عليك أولا إنشاء ملف INI واحفظه باسم "C:\DB.ini" . أنشئ فيه قسم باسم INIDB واضف إليه المفاتيح والقيم التالية :

[INIDB]
; Save as C:\DB.ini
Author=Adam
Pass=
DBFile=C:\Money.dat

واﻵن لننتقل إلي الكود ..

Program IniSample;

{$mode objfpc}{$H+}

Uses
  Classes,SysUtils,INIFiles;

Var
 INI:TINIFile;
 Author,Pass,DBFile:String;
 PassEnter:String;

begin
  // Create the object, specifying the place where it can find the ini file:
  INI := TINIFile.Create('C:\DB.ini');
  // Demonstrates reading strings from the INI file.
  // You can also read booleans etc.
  Author := INI.ReadString('INIDB','Author','');
  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;
  // After we used ini file, we must call the Free method of object
  // ... although this really should be wrapped in a try..finally block
  // so that the object will be freed regardless of any errors above.
  Ini.Free; 
end.

أشياء لابد أن تعرفها

تحتوي الفئة TINIFile علي كثير من الخصائص واﻷجراءات والدوال اللتي يمكن استخدامها .

CaseSensitive - تتيح لك هذه الخاصية أن تجعل المفاتيح واﻷقسام حساسة لحالة اﻷحرف أم لا , افتراضيا غير حساسة لحالة اﻷحرف.


ReadString - تأخذ 3 مدخلات , اﻷول هو القسم اللذي يجب البحث فيه والثاني هو المفتاح اللذي سيتم البحث عنه والثالث هو قيمة افتراضية حال أن القسم و/أو المفتاح المطلوبين غير موجودين


WriteString - تأخذ 3 مدخلات أيضا , اﻷول هو القسم والثاني المفتاح والثالث هو القيمة المراد اسنادها لهذا المفتاح , لاحظ أنه إذا كان المفتاح والقسم موجودين من قبل فأنه سيتم كتابة القيمة الجديدة فوق القديمة .

ReadSections - تسمح لك بأخذ جميع اﻷقسام من ملف INI في صورة TString أو TStringList عن طريق المعامل As .

DeleteKey - تمكنك من حذف مفتاح موجود داخل أحد اﻷقسام .

EraseSection - تمكنك من حذف قسم كامل بكل محتوياته .


وغير ذلك يوجد الكثير من اﻷجراءات والدوال ولكن ماسبق يكفي لكي تبدأ .

المراجع

هنا: Free Pascal documentation on INI files


شاهد أيضا