الرجاء توضيح الفرق بين الModule و Class Module
افيدونا جزاكم الله خيراً
الرجاء توضيح الفرق بين الModule و Class Module
افيدونا جزاكم الله خيراً
ال module يمكن استخدامه لوضع كود سيتم استعماله في البرنامج كاملا و ليس من الضروري كتابة اسم ال module للوصول الى الدالات هناك مثل
هذا الكود في فورم
Public sub SayHi() msgbox "HI" end sub
اذا اردت استعماله من فوم اخر يتم كتابة هذا الكود
FrmHello.SayHi
اما اذا كان الكود التابع للدالة SayHi في Module فيمكن استدعاؤه هكذا
SayHi
لاحظ اني لم استخدم اسم الmodule
اما عن ال Class Module فهو مثل ال Custom Data Type والمذكور نوع من انواع المتغيرات. اذا استخدمت ال DLL Files من قبل فستعرف انه يمكن استخدام الدالات في هذا الملف بعمل Object عن ال Class المستخدم في هذا الملف
Dim MyObject as New MyClassModule MyObject.SayHi
ارجو ان اكون قد افدت في الشرح واسف اذا قصرت
معلومات اكثر:
اقتباسStandard Module =- A dumping ground for public variables, public enumerations, public types, and public subs/functions
- Code placed here that's not typed as PRIVATE can be accessed from anywhere in your project
- Standard modules do NOT need to be initialized... simply call the functions it contains directly
Class Module =
- These are objects that have to be initialized ( i.e. Set MyVariable = New MyClass )
- These objects have to be cleaned up or terminated once they are no longer needed ( i.e. Set MyVariable = Nothing )
- Class modules automatically call a privately declared sub called "Class_Initialize" (no parameters) whenever they are SET. This allows you to initialize any variables or information related to your class.
- Class modules automatically call a privately declared sub called "Class_Terminate" (no parameters) whenever they are destroyed (set equal to NOTHING). This allows you to clean up any objects, variables, or information related to your class.
- Class modules can be used to maintain "state" when it comes to information relating to your class. This means if you want to set the last accessed date of a property or sub... you can. You can maintain if the class is open, closed, pending, etc. and it remembers that (via Properties).
- Class modules are usually used to encaposlate complex tasks and give you easy interfaces to them (take a look at some of the classes I have posted on my web site)
منقول من
تم تعديل هذه المشاركة بواسطة راكان الحنيطي في 1 يونيو 2004 في 19:40
راكان الحنيطي
Be Open Source

الموديول أو الوحدة النمطية .. تحتوي عى توابع وإجراءات من نوعين أساسيين:
عامة/Public : يتم استدعاؤها من جميع أجزاء البرنامج من خلال اسمها فقط كما ذكر أخي راكان
خاصة/Private : تستدعيها الإجراءات من نفس الموديول
كما يتم تعريف متحولات عامة في أولها وأنواع و ENum تكون معروفة في جميع أجزاء البرنامج
أما Class Module أو وحدة الصنف .. فيتم داخلها تعريف صنف معين ... ويكون لكل صنف اسم يميزه ويحتوي الصنف على إجراءات ودالات خاصة به وعلى خصائص Property وأحداث Events .. ويتم التعامل معها كلها من خلال عنصر من الصنف يتم تعريفه كما ذكر أخي راكان كما يلي :
Dim MyObject as New MyClassModule
معنى ذلك أننا عرفنا متحول باسم MyObject من النوع MyClassModule وهذا النوع هو عبارة عن صنف تم تصميمه في Class Module
وتستخدم الأصناف بكثرة في البرمجة غرضية التوجه .. حيث يتم تقسيم البرنامج إلى مجموعة أصناف وتتم برمجة كل صنف على حدة
وهذا يعطي البرنامج قوة إضافية من حيث سهولة التعديل والصيانة والتحديث
هذا الموضوع مغلق.