Иллюстрированный самоучитель по Kylix

       

Полный листинг для нового компонента



Листинг 19.7. Полный листинг для нового компонента

unit QMyButton;
interface
uses
SysUtils, Types, Classes, QGraphics, QControls, QForms, QDialogs, QStdCtrls;
type
TMyObject = class (TPersistent) private
{ Private declarations }
FProperty1:Real;
FProperty2:Char; protected
{ Protected declarations }
public
{ Public declarations }
procedure Assign (Source: TPersistent);
published
{ Published declarations }
property Property1: Real read FProperty1 writhe FProperty1;
property Property2: Char read FProperty2 write FProperty2; end;
type
TMyButton = class(TButton) private
{ Private declarations }
FMyObject:TMyObject;
procedure SetMyObject (Value: TMyObject);
protected
{ Protected declarations } public
{ Public declarations }
constructor Create (AOwner: TComponent);
override; destructor Destroy; override; published
{ Published declarations }
property MyObject: TMyObject read FMyObject write SetMyObject; end; procedure Register;
implementation
procedure Register; begin
RegisterComponents('Samples', [TMyButton]);
end;
procedure TMyButton.SetMyObject(Value: TMyObject);
begin
if Assigned(Value) then FMyObject.Assign(Value);
end;
constructor TMyButton.Create(AOwner: TComponent);
begin
inherited Create (AOwner);
FMyObject:=TMyObject.Create; end;
destructor TMyButton.Destroy; begin
FMyObject.Free;
inherited Destroy; end;
procedure TMyObject.Assign(Source: TPersistent);
begin if Source is TMyObject then begin
FProperty1:=TMyObject(Source).Property1; FProperty2: = TMyObject (Source) .Property2; inherited Assign (Source);
end; end;
end.



Содержание раздела