Solved

create a component

Posted on 2004-08-17
6
286 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Title # Comments Views Activity
Create Database on Android via Delphi dbExpress 3 115
Run video youtube webbrowse 10 65
Reconfigure Delphi Install? 2 61
PHP preg_replace code convert to Delphi 14 67
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

829 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