Solved

create a component

Posted on 2004-08-17
6
284 Views
Last Modified: 2010-04-05
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('Samples', [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.Create(Owner);
   with CentralPanel do
     begin
        Name:='lbl_' + inttostr (self.ControlCount);
        Top:= 47;
        Left:=10;
        Color:=clSilver;
        Visible:=True;
    end;
end;


end.





0
Comment
Question by:BaTy_GiRl
6 Comments
 
LVL 7

Accepted Solution

by:
LRHGuy earned 20 total points
ID: 11820321
Try adding:

  CentralPanel.Parent:=Self;

to make the panel show up on the form. Or assigned the parent as the other panel you want it to show up on.

Panel1:=tPanel.Create(form1);
panel1.parent:=form1;
panel2:=tPanel.Create(form1);
panel2.parent:=panel1;  //will be inside panel1 !
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 11820354
constructor TMachine.Create(Owner: TComponent);
begin
   inherited Create(Owner);  // Initialize inherited parts (TPanel)
   Width := 144;  // Change inherited properties
   Height := 166;
   Color:=clBtnFace;
   CentralPanel:=TPanel.Create(Owner);
   with CentralPanel do
     begin
       Parent:= Owner;  //********
       Name:='lbl_' + inttostr (self.ControlCount);
        Top:= 47;
        Left:=10;
        Color:=clSilver;
        Visible:=True;
    end;
end;

Shane
0
 

Author Comment

by:BaTy_GiRl
ID: 11820397
Thank you very much the wrong was with

CentralPanel.Parent:=Self;
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 4

Expert Comment

by:ceoworks
ID: 11820497
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.
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 11820508
Ohh i'm late :)

Cheers,

Oktay
0
 

Author Comment

by:BaTy_GiRl
ID: 11820660
anyway thank u very much, i did'n make a destructor
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now