Solved

Create a customer TPanel component

Posted on 2007-03-30
5
320 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

24 Experts available now in Live!

Get 1:1 Help Now