Using INI Files/ar: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: Using INI Files/ar
| Old | New | Line | |
|---|---|---|---|
| 1 | + | ## ملفات اﻷعدادات INI | |
| 2 | + | ||
| 3 | + | ### معلومات أساسية | |
| 4 | + | ||
| 5 | + | تستخدم ملفات INI لحفظ إعدادات المستخدم اﻷساسية بسهولة , فعن طريق الوحدة **INIfiles** و الفئة **TINIFile** يمكنك بكل سهولة التعامل مع ملفات INI الموجودة مسبقا , تجد هذه الوحدة ضمن مكتبات FCL | |
| 6 | + | ||
| 7 | + | ### ملفات INI | |
| 8 | + | ||
| 9 | + | تستخدم ملفات INI الأقواس لتحديد **اﻷقسام** واللتي بدورها تحتوي علي **مفاتيح** و **قيم** . | |
| 10 | + | ||
| 11 | + | يتم الفصل بين المفتاح والقيمة المقابلة له بعلامة التساوي (المفتاح=القيمة). | |
| 12 | + | ||
| 13 | + | أسماء اﻷقسام تكتب بين قوسين مربعين ج\[قسم\]. | |
| 14 | + | ||
| 15 | + | التعليقات دائما مسموح بها ويسبق سطر التعليق بعلامة الفاصلة المنقوطة (;) ,وبماأن ملفات INI ليست قياسية بشكل كامل فأنه يمكن استخدام رموز التعليق اﻷخري كعلامة \# . | |
| 16 | + | ||
| 17 | + | حاليا يتم أستخدام ملفات INI أقل من أستخدام ملفات xml لتخزين السلاسل النصية , لأن ملفات INI لا تستطيع معالجة النصوص الكبيرة بشكل جيد. | |
| 18 | + | ||
| 19 | + | مثال علي ملف INI : | |
| 20 | + | ||
| 21 | + | ``` ini | |
| 22 | + | ; Comment. Beginning of INI file | |
| 23 | + | ||
| 24 | + | ; empty lines are ignored | |
| 25 | + | ||
| 26 | + | ; note that no section has been defined. | |
| 27 | + | Compiler=Delphi | |
| 28 | + | ; Key: Compiler | |
| 29 | + | ; Value: Delphi | |
| 30 | + | ||
| 31 | + | [General] | |
| 32 | + | ; This starts a General section | |
| 33 | + | Compiler=FreePascal | |
| 34 | + | ; Key Compiler and value FreePascal | |
| 35 | + | ``` | |
| 36 | + | ||
| 37 | + | ### مثال قراءة ملف INI | |
| 38 | + | ||
| 39 | + | التطبيق التالي يوضح كيفية قراءة ملف INI , عليك أولا إنشاء ملف INI واحفظه باسم "C:\DB.ini" . أنشئ فيه قسم باسم INIDB واضف إليه المفاتيح والقيم التالية : | |
| 40 | + | ||
| 41 | + | ``` ini | |
| 42 | + | [INIDB] | |
| 43 | + | ; Save as C:\DB.ini | |
| 44 | + | Author=Adam | |
| 45 | + | Pass= | |
| 46 | + | DBFile=C:\Money.dat | |
| 47 | + | ``` | |
| 48 | + | ||
| 49 | + | واﻵن لننتقل إلي الكود .. | |
| 50 | + | ||
| 51 | + | ``` pascal | |
| 52 | + | Program IniSample; | |
| 53 | + | ||
| 54 | + | {$mode objfpc}{$H+} | |
| 55 | + | ||
| 56 | + | Uses | |
| 57 | + | Classes,SysUtils,INIFiles; | |
| 58 | + | ||
| 59 | + | Var | |
| 60 | + | INI:TINIFile; | |
| 61 | + | Author,Pass,DBFile:String; | |
| 62 | + | PassEnter:String; | |
| 63 | + | ||
| 64 | + | begin | |
| 65 | + | // Create the object, specifying the place where it can find the ini file: | |
| 66 | + | INI := TINIFile.Create('C:\DB.ini'); | |
| 67 | + | // Demonstrates reading strings from the INI file. | |
| 68 | + | // You can also read booleans etc. | |
| 69 | + | Author := INI.ReadString('INIDB','Author',''); | |
| 70 | + | Pass := INI.ReadString('INIDB','Pass',''); | |
| 71 | + | DBFile := INI.ReadString('INIDB','DBFile',''); | |
| 72 | + | if Pass <> '' then | |
| 73 | + | begin | |
| 74 | + | Writeln('Password Required'); | |
| 75 | + | Repeat | |
| 76 | + | Readln(PassEnter); | |
| 77 | + | if not (PassEnter = Pass) then Writeln('Wrong Password'); | |
| 78 | + | until(PassEnter = Pass); | |
| 79 | + | Writeln('Correct Password'); | |
| 80 | + | end; | |
| 81 | + | Writeln('Author : '+Author); | |
| 82 | + | Writeln('File : '+DBFile); | |
| 83 | + | Writeln('Password : '+Pass); | |
| 84 | + | Readln; | |
| 85 | + | // After we used ini file, we must call the Free method of object | |
| 86 | + | // ... although this really should be wrapped in a try..finally block | |
| 87 | + | // so that the object will be freed regardless of any errors above. | |
| 88 | + | Ini.Free; | |
| 89 | + | end. | |
| 90 | + | ``` | |
| 91 | + | ||
| 92 | + | ### أشياء لابد أن تعرفها | |
| 93 | + | ||
| 94 | + | تحتوي الفئة TINIFile علي كثير من الخصائص واﻷجراءات والدوال اللتي يمكن استخدامها . | |
| 95 | + | ||
| 96 | + | **CaseSensitive** - تتيح لك هذه الخاصية أن تجعل المفاتيح واﻷقسام حساسة لحالة اﻷحرف أم لا , افتراضيا غير حساسة لحالة اﻷحرف. | |
| 97 | + | ||
| 98 | + | **ReadString** - تأخذ 3 مدخلات , اﻷول هو القسم اللذي يجب البحث فيه والثاني هو المفتاح اللذي سيتم البحث عنه والثالث هو قيمة افتراضية حال أن القسم و/أو المفتاح المطلوبين غير موجودين | |
| 99 | + | ||
| 100 | + | **WriteString** - تأخذ 3 مدخلات أيضا , اﻷول هو القسم والثاني المفتاح والثالث هو القيمة المراد اسنادها لهذا المفتاح , لاحظ أنه إذا كان المفتاح والقسم موجودين من قبل فأنه سيتم كتابة القيمة الجديدة فوق القديمة . | |
| 101 | + | ||
| 102 | + | **ReadSections** - تسمح لك بأخذ جميع اﻷقسام من ملف INI في صورة TString أو TStringList عن طريق المعامل As . | |
| 103 | + | ||
| 104 | + | **DeleteKey** - تمكنك من حذف مفتاح موجود داخل أحد اﻷقسام . | |
| 105 | + | ||
| 106 | + | **EraseSection** - تمكنك من حذف قسم كامل بكل محتوياته . | |
| 107 | + | ||
| 108 | + | وغير ذلك يوجد الكثير من اﻷجراءات والدوال ولكن ماسبق يكفي لكي تبدأ . | |
| 109 | + | ||
| 110 | + | ### المراجع | |
| 111 | + | ||
| 112 | + | هنا: [Free Pascal documentation on INI files](http://lazarus-ccr.sourceforge.net/docs/fcl/inifiles/index.html) | |
| 113 | + | ||
| 114 | + | ## شاهد أيضا | |
| 115 | + | ||
| 116 | + | - [[XML Tutorial]] | |
| 117 | + | ||
| 118 | + | --- | |
| 119 | + | *From the Free Pascal wiki, page "Using INI Files/ar", as it stood on 2020-03-04 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
