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
Solved

Create a customer TPanel component

Posted on 2007-03-30
5
324 Views
Last Modified: 2013-11-23
Hi all,

I am trying to create a custom TPanel component.
On the panel i require another panel at the top and a Listview at the bottom.
The size of the main panel is only going to be 100x100.

I need it this way as I need 26 of these components on 1 page, plus I can store specific objects against each of the components.

Having trouble getting this to work so any help appreciated.
0
Comment
Question by:mikelittlewood
  • 2
  • 2
5 Comments
 
LVL 17

Expert Comment

by:mokule
ID: 18823271
Maybe Frame is a good choice?
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 18823324
I don't know he he .. never has to make a component within a component   :o)
0
 
LVL 15

Author Comment

by:mikelittlewood
ID: 18823372
Personally I would rather have an example of an extended panel than using a frame if someone had some code.
0
 
LVL 17

Expert Comment

by:mokule
ID: 18823373
So try to create a frame.
File | New | Frame
place any component on it
And then on each form of Your application You can place using Frame component from Standard components
0
 
LVL 17

Accepted Solution

by:
TheRealLoki earned 125 total points
ID: 18833024
here's an example I wrote for you.
You can easily turn this into a VCL (so you can use it in design mode) by adding a "register" method

unit Unit1;

interface


uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ExtCtrls, ComCtrls, StdCtrls;

type TMyPanel = class(TPanel)
  public
    TopPanel: TPanel;
    ListView: TListView;
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
end;

type
  TForm1 = class(TForm)
    Button_Make26Panels: TButton;
    procedure Button_Make26PanelsClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

{ TMyPanel }

constructor TMyPanel.Create(AOwner: TComponent);
const
  def_mainpanelheight = 100;
  def_mainpanelwidth = 100;
  def_toppanelheight = 50;
begin
  inherited Create(AOwner);
  self.Height := def_mainpanelheight;
  self.Width := def_mainpanelwidth;
  TopPanel := TPanel.Create(self);
  with TopPanel do
  begin
    Parent := self;
    Height := def_toppanelheight;
    Align := alTop;
  end;
  ListView := TListView.Create(self);
  with ListView do
  begin
    Parent := self;
    Align := alClient;
  end;
end;

destructor TMyPanel.Destroy;
begin
  if assigned(TopPanel) then FreeAndNil(TopPanel);
  if assigned(ListView) then FreeAndNil(ListView);
  inherited Destroy;
end;

procedure TForm1.Button_Make26PanelsClick(Sender: TObject);
var
  col, row: integer;
  newpanel: TMyPanel;
  i: integer;
begin
  i := 0;
  for col := 1 to 13 do
    for row := 1 to 13 do
    begin
      inc(i);
      newpanel := TMyPanel.Create(Form1);
      with newpanel do
      begin
        Left := (col-1) * 102;
        top := (row-1) * 102;
        TopPanel.Caption := IntToStr(i);
        Parent := Form1;
      end;
    end;
end;

end.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
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…

839 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