PDA

View Full Version : اضافه کردن خاصیت جدید به اشیاء



پریسا دوستدار دلفی
یک شنبه 04 مرداد 1383, 21:40 عصر
من میخوام به CheckBox و یک Button خاصیت OnDblClick را اضافه کنم
چگونه اینکار را انجام دهم

SReza1
دوشنبه 05 مرداد 1383, 00:46 صبح
به نظز من بهتره که شما یک کامپیونتت از checkbox و یکی از buttom به ارث ببری(بسازی)
بعد property مورد نظر رو به اونا اضافه کنی!
من نمیدونم این object جدید چه خاصیتی داره که شما دنباله ساخت اونید؟ :shock: :shock: :!:

سار
دوشنبه 05 مرداد 1383, 01:08 صبح
من میخوام به CheckBox و یک Button خاصیت OnDblClick را اضافه کنم
چگونه اینکار را انجام دهم

اینها مگه خودشون این خاصیتها رو ندارن :!:

nasr
دوشنبه 05 مرداد 1383, 14:26 عصر
در قسمت کارگاه دلفی یک بحث در مورد همین کار داره
می تونید اونجا را یه نگاه بندازید شاید برایتان مفید باشه

پریسا دوستدار دلفی
دوشنبه 05 مرداد 1383, 17:58 عصر
به نظز من بهتره که شما یک کامپیونتت از checkbox و یکی از buttom به ارث ببری(بسازی)
بعد property مورد نظر رو به اونا اضافه کنی!
اینکار را چطوری انجام بدم لطفا کامل توضیح بدید چون تا حالا اینکار را نکرده ام و اصلا نمیدونم



اینها مگه خودشون این خاصیتها رو ندارن
می تونید خودتون نگاه کنید
دلفی من که نداره :wink:

jirjirakk
دوشنبه 05 مرداد 1383, 20:05 عصر
یک نمونه کوچیک نوشتم اما تستش نکردم، خودت بگیرش کاملش کن ...


unit QTCheckBox;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;

type
TImage1 = class(TImage)
private
FOnDBClick: TNotifyEvent;
procedure CMMDBClick(var Message: TMessage); message CM_??????;
published
property OnDBClick: TNotifyEvent read FOnDBClick write FOnDBClick;
end;

procedure Register;

implementation

procedure Register;
begin
RegisterComponents('Samples', [TCheckBoxxxxx]);
end;

procedure TImage1.CMMDBClick(var Message: TMessage);
begin
inherited;
if Assigned(FOnDBClick) then FOnDBClick(Self);
end;

end.


البته صحت درست بودن یا نبودنش و نمیدونم، آخه خودمم تازه شروع کردم از این جور کارا

jirjirakk
دوشنبه 05 مرداد 1383, 20:08 عصر
راستی این همون چیزی بود که سید گفته بود.

SReza1
دوشنبه 05 مرداد 1383, 22:41 عصر
کارگاه دلفی رو نگاه کن! جوابت اونجاست :? :o

moradi_am
سه شنبه 06 مرداد 1383, 07:21 صبح
این را من اتفاقی دیروز دانلود کردم شاید بدردتان بخورد :

>This works well unless the class you are deriving from has used the
>same name for a property/function/proc/field that you need access to
>in one its base classes.
>
>Case in point: I decided I needed transparency for my TImages, so I
>derived a class TTransparentImage = class( TImage ). Unfortunately,
>the only way I could get the thing to work (using masked blits,
>following Jay Giganti's TWIATile class) was to have direct access to
>the Canvas property of TImage's base class, TGraphicControl.
>
>Unfortunately, TImage also defines a Canvas property which it ties to
>its Picture's Bitmap's Canvas. In C++, I would have accessed the
>Canvas I want like TGraphicControl::Canvas, but I've been informed
>there's no euqivalent scope operator in Object Pascal.
>
>My solution, therefore, was to modify the VCL, creating a new property
>for TImage, InheritedCanvas, that returned what I wanted.
>
>I'll take any suggestions as to how to get around the name hiding
>under inheritance problem.

You can cast a descendant object as an ancestor and then access its
(non-private) methods and data.
Step through the code below with the debugger. Add watches for Derived.Prop
and TBase(Derived) (the debugger doesn't like "Derived as TBase") and a.

{interface}
{type}
TBase =class(TObject)
private
FProp: integer;
public
property Prop: integer read FProp write FProp;
end;

TDerived =class(TBase)
private
FProp: integer;
public
property Prop: integer read FProp write FProp; {same definition!}
end;


{implementation}
procedure TForm1.Button1Click(Sender: TObject);
var
Derived: TDerived;
a: integer;
begin
Derived := TDerived.Create;

Derived.Prop := 10;
(Derived as TBase).Prop := 20;
a := (Derived as TBase).Prop;
a := Derived.Prop;

Derived.free;

end;