Sign in Join
Wiki copytemporary

File Handling In Pascal/ar: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-<div dir="rtl" style="text-align: right;">
2-
31## نظرة عامة
42
53يجب ان يتعلم جميع المبرمجين كيفية التعامل مع الملفات.تستخدم الملفات لحفظ المعلومات بحيث يمكن استرجاعها مرة اخرى
64
75## الطريقة الهيكلية القديمة
86
97عند التعامل مع الملفات بطريق هيكلية (غير شيئية) يمكن تحديد نوع الملف حسب المحتويات التي نرغب بتخزينها( او المخزنة مسبقا) في الملف مثلا للنصوص نستخدم TextFile والذي يقوم بحفظ النص بشكل اسطر كل سطر ينتهي بعلامة انتهاء السطر([[End of Line|LineEnding]]). يمكنك حفظ مقاطع نصية (String)في هذا النوع من الملفات كما يمكن حفظ الارقام ايضا بعد تحوليها الى String. يمكنك انشاء نوعك الخاص من الملفات لحفظ نوع معين من البيانات :لتخزين الارقام فقط. هذا الملف يستخدم لحفظ ذلك النوع فقط مثال:
108
11-<div dir="rtl" style="text-align: left;">
12-
139``` pascal
1410...
1511type
1612 TIntegerFile = file of integer; // يسمح لك فقط بكتابة ارقام Integer في الملف
1713 TExtendedFile = file of extended; // يسمح لك فقط بكتابة ارقام extended في الملف
1814 TCharFile = file of char; // يسمح لك فقط بكتابة حروف منفردة char في الملف
1915
2016//يمكن ايضا انشاء ملف من نوع سجل
2117TCostumer = record
2218 CostumerName: string[255];
2319 CostumerID: Integer;
2420end;
2521TCostumerFile = file of TCostumer;
2622```
2723
28-<div dir="rtl" style="text-align: right;">
29-
3024## التعامل مع اخطاء الادخال و الاخراج
3125
3226العلم[I/O error handling flag](http://www.freepascal.org/docs-html/prog/progsu38.html#x45-440001.2.38)يخبر المصنف(compiler) بطريقة التعام مع الاخطاء اما برفع استثناء او حفظ النتيجة في اللمتغير IOResult
3327
34-<div dir="rtl" style="text-align: left;">
35-
3628``` pascal
3729{$I+} // الاخطاء ستقوم برفع استثناء(الافتراضي)
3830{$I-} //IOResult يتم وضع الخطأ في المتغير
3931```
4032
41-<div dir="rtl" style="text-align: right;">
42-
4333## اجراءات الملفات
4434
4535اجلراءات ودوال التعامل مع الملفات التاية موجودة في الوحدة System. يمكنك الذهاب الى الوثائق للمزيد من المعلومات [Reference for 'System' unit](http://www.freepascal.org/docs-html/rtl/system/index-5.html).
4636
4737- **AssignFile** تحديد اسم الملف
4838- **Append** فتح ملف موجود للاضافة اليه
4939- **BlockRead** - قراءة معلوات من ملف غير محدد النوع الى الذاكرة
5040- **BlockWrite** - كتابة معلومات من الذاكرة الى ملف غير محدد النوع
5141- **CloseFile** اغلاق الملف
5242- **EOF** - فحص نهاية الملف
5343- **Erase** - حذف ملف من القرص
5444- **FilePos**
5545- **FileSize** - هذه الدالة تعطي حجم الملف
5646- **Flush** -
5747- **IOResult** - نتيج اخر عملية ادخال او اخراج
5848- **Read** - القراءة من ملف
5949- **ReadLn** - قراءة سطر من الملف
6050- **Reset** - فغتح ملف للقراءة
6151- **Rewrite** - انشاء ملف للكتابة
6252- **Seek** - تغير المكان(مكان القراءة او الكتابة)في الملف
6353- **SeekEOF** - الذهاب الى نهاية الملف
6454- **SeekEOLn** - الذهاب الى نهاية السطر
6555- **Truncate** -
6656- **Write** - كتابة متغير في الملف
6757- **WriteLn** - كتابة متغير في ملف نصي والذهاب الى ملف جديد
6858
6959## مثال
7060
7161مثال لملف نصي TextFile
72-
73-<div dir="rtl" style="text-align: left;">
7462
7563``` pascal
7664program CreateFile;
7765
7866uses
7967 Sysutils;
8068
8169const
8270 C_FNAME = 'textfile.txt';
8371
8472var
8573 tfOut: TextFile;
8674
8775begin
8876 // Set the name of the file that will be created
8977 AssignFile(tfOut, C_FNAME);
9078
9179 // Use exceptions to catch errors (this is the default so not absolutely requried)
9280 {$I+}
9381
9482 // Embed the file creation in a try/except block to handle errors gracefully
9583 try
9684 // Create the file, write some text and close it.
9785 rewrite(tfOut);
9886
9987 writeln(tfOut, 'Hello textfile!');
10088 writeln(tfOut, 'The answer to life, the universe and everything: ', 42);
10189
10290 CloseFile(tfOut);
10391
10492 except
10593 // If there was an error the reason can be found here
10694 on E: EInOutError do
10795 writeln('File handling error occurred. Details: ', E.ClassName, '/', E.Message);
10896 end;
10997
11098 // Give feedback and wait for key press
11199 writeln('File ', C_FNAME, ' created if all went ok. Press Enter to stop.');
112100 readln;
113101end.
114102```
115103
116104---
117105*From the Free Pascal wiki, page "File Handling In Pascal/ar", as it stood on 2020-02-14 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).*

Back to history