Solved

Create a customer TPanel component

Posted on 2007-03-30
5
325 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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
Magic Software info 18 142
TServerSocket - file via sendbuf or Text via sendtext ? 1 76
Performance of SQL statement 37 137
Tidtcpserver listening on multiports? 1 41
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

680 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