Solved

create a component

Posted on 2004-08-17
6
283 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you very much the wrong was with

CentralPanel.Parent:=Self;
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 4

Expert Comment

by:ceoworks
Comment Utility
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
Comment Utility
Ohh i'm late :)

Cheers,

Oktay
0
 

Author Comment

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

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

743 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

19 Experts available now in Live!

Get 1:1 Help Now