Solved

create a component

Posted on 2004-08-17
6
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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