BaTy_GiRl
asked on
create a component
hi there....
I have a problem, i need to make a control wich has a TPanel inside another TPanel but i cant,
i have tryed at diferent ways, but it shows errors, or only show me the first panel....
could anybody help me with the syntax, i create the second panel inside constructor....
but it marks errors
unit Machine;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,QGraphics;
type
TMachine = class(TPanel)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
CentralPanel:TPanel;
constructor Create(Owner: TComponent); override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Sample s', [TMachine]);
end;
constructor TMachine.Create(Owner: TComponent);
begin
inherited Create(Owner); // Initialize inherited parts (TPanel)
Width := 144; // Change inherited properties
Height := 166;
Color:=clBtnFace;
CentralPanel:=TPanel.Creat e(Owner);
with CentralPanel do
begin
Name:='lbl_' + inttostr (self.ControlCount);
Top:= 47;
Left:=10;
Color:=clSilver;
Visible:=True;
end;
end;
end.
I have a problem, i need to make a control wich has a TPanel inside another TPanel but i cant,
i have tryed at diferent ways, but it shows errors, or only show me the first panel....
could anybody help me with the syntax, i create the second panel inside constructor....
but it marks errors
unit Machine;
interface
uses
SysUtils, Classes, Controls, ExtCtrls,QGraphics;
type
TMachine = class(TPanel)
private
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
CentralPanel:TPanel;
constructor Create(Owner: TComponent); override;
published
{ Published declarations }
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('Sample
end;
constructor TMachine.Create(Owner: TComponent);
begin
inherited Create(Owner); // Initialize inherited parts (TPanel)
Width := 144; // Change inherited properties
Height := 166;
Color:=clBtnFace;
CentralPanel:=TPanel.Creat
with CentralPanel do
begin
Name:='lbl_' + inttostr (self.ControlCount);
Top:= 47;
Left:=10;
Color:=clSilver;
Visible:=True;
end;
end;
end.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much the wrong was with
CentralPanel.Parent:=Self;
CentralPanel.Parent:=Self;
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
public
{ Public declarations }
end;
TMyPanel = class(TPanel)
private
FInsidePanel: TPanel;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
Form1: TForm1;
MyPanel: TMyPanel;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyPanel := TMyPanel.Create(Form1);
with MyPanel do
begin
Color := clBlue;
Left := 5;
Top := 5;
Height := 100;
Width := 100;
Parent := Self;
Visible := True;
end;
end;
{ TMyPanel }
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited;
Color := clBlue;
FInsidePanel := TPanel.Create(Self);
with FInsidePanel do
begin
Color := clRed;
Height := 50;
Width := 50;
Parent := Self;
Visible := True;
end;
end;
destructor TMyPanel.Destroy;
begin
inherited;
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
private
public
{ Public declarations }
end;
TMyPanel = class(TPanel)
private
FInsidePanel: TPanel;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
end;
var
Form1: TForm1;
MyPanel: TMyPanel;
implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
MyPanel := TMyPanel.Create(Form1);
with MyPanel do
begin
Color := clBlue;
Left := 5;
Top := 5;
Height := 100;
Width := 100;
Parent := Self;
Visible := True;
end;
end;
{ TMyPanel }
constructor TMyPanel.Create(AOwner: TComponent);
begin
inherited;
Color := clBlue;
FInsidePanel := TPanel.Create(Self);
with FInsidePanel do
begin
Color := clRed;
Height := 50;
Width := 50;
Parent := Self;
Visible := True;
end;
end;
destructor TMyPanel.Destroy;
begin
inherited;
end;
end.
Ohh i'm late :)
Cheers,
Oktay
Cheers,
Oktay
ASKER
anyway thank u very much, i did'n make a destructor
begin
inherited Create(Owner); // Initialize inherited parts (TPanel)
Width := 144; // Change inherited properties
Height := 166;
Color:=clBtnFace;
CentralPanel:=TPanel.Creat
with CentralPanel do
begin
Parent:= Owner; //********
Name:='lbl_' + inttostr (self.ControlCount);
Top:= 47;
Left:=10;
Color:=clSilver;
Visible:=True;
end;
end;
Shane