Solved

create a component

Posted on 2004-08-17
6
285 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

816 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

12 Experts available now in Live!

Get 1:1 Help Now