PDA

View Full Version : متدهای Published Protected Public Private



Developer Programmer
چهارشنبه 10 فروردین 1384, 13:59 عصر
متاسفانه هر مرجع ، تعریف خاص خود را بکار برده ... خواهشمندم بطور کامل و دقیق توضیح دهید

1) متدهای Published Protected Public Private در چه مواقعی به کار میروند و چه تفاوت هایی دارند؟
2) چرا Property ها در Published تعریف میشوند؟

3)


type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

آنچه که قبل از Private تعریف شده (مثل button1) جزو کدام دسته بحساب می آیند(منظورم private , public , … است )

4) وقتی در هنگام تعریف تابعی جلوی آن virtual مینویسیم چه عملی را قرار است انجام دهد؟

مهدی کرامتی
چهارشنبه 10 فروردین 1384, 16:36 عصر
<span dir=ltr>
A private member is invisible outside of the unit or program where its class is declared. In other words, a private method cannot be called from another module, and a private field or property cannot be read or written to from another module. By placing related class declarations in the same module, you can give the classes access to one another's private members without making those members more widely accessible.

A protected member is visible anywhere in the module where its class is declared and from any descendant class, regardless of the module where the descendant class appears. A protected method can be called, and a protected field or property read or written to, from the definition of any method belonging to a class that descends from the one where the protected member is declared. Members that are intended for use only in the implementation of derived classes are usually protected.

A public member is visible wherever its class can be referenced.

Published members have the same visibility as public members. The difference is that runtime type information (RTTI) is generated for published members. RTTI allows an application to query the fields and properties of an object dynamically and to locate its methods. RTTI is used to access the values of properties when saving and loading form files, to display properties in the Object Inspector, and to associate specific methods (called event handlers) with specific properties (called events).</span>


آنچه که قبل از Private تعریف شده (مثل button1) جزو کدام دسته بحساب می آیند
جزو هیچکدام. به اینها میگن Designer Generated Code و برای حفظ رابطه عناصری که در فایل فرم (<span dir=ltr>*.DFM</span>) تعریف شده اند با کد معادل در یونیت مربوطه استفاده میشوند.

مهدی کرامتی
پنج شنبه 11 فروردین 1384, 11:53 صبح
همانطور که میدانید دلفی کلا از دو بخش تشکیل شده است:

1- محیط توسعه
2- کتابخانه کلاسها و توابع

محیط توسعه میبایست این قابلیت را داشته باشد که بتواند مشخصات عمومی کلاسها را استخراج کند تا از آنها برای ارائه اطلاعات به توسعه گر استفاده کند (معروف ترین روش ارائه این اطلاعات پنجره Object Inspector است). برای عملی کردن این نیاز دلفی مجهز به سیستمی معروف بنام Run Time Type Information است.

وقتی که شما Method یا Property ای را در بخش Published تعریف میکنید به این معناست که از IDE دلفی میخواهید که آنها را جهت نمایش در مکانهای مربوطه فهرست کند.