?
Solved

Creating component

Posted on 2004-03-30
3
Medium Priority
?
159 Views
Last Modified: 2010-04-05
Hello,

Is it possible to create somekind like a "wrapper" for an object?

I meant, we know TButton object, it has some properties like :
- caption
- left
- top

I want to create another TButton component that will have PRESET value :
- caption = "Click me"
- left = 100
- top = 100

Everytime I add this component into a form, it will have those propertie's values.

Also, is it possible to create somekind of "compound" object? For example, if I add this component into a form, it will create TWO buttons and a listbox.

Thanks.
0
Comment
Question by:nova2002
[X]
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
  • 3
3 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10718967


 TMyButton = class(TButton)
 public
  Constructor Create(AOwner: TComponent);override;
 end;

  ConstructorTMyButton.Create(AOwner: TComponent);override;
  begin
   inherited Create(AOwner);
   Caption:-= 'Click Me';
   Left:= 100;
   Top:= 100;
  end;


Shane
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10718977
Yes it is possible to create compound objects?

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 320 total points
ID: 10719099
SOmething like


This is a Panel with a Button and Listbox

Quick sample

Shane


unit ExtPanel1;

interface

uses
  SysUtils, Classes, Controls, ExtCtrls, StdCtrls;

type
  TExtPanel1 = class(TPanel)
  private
    { Private declarations }
    fButton: TButton;
    fListBox: TListBox;
  protected
    { Protected declarations }
  public
    { Public declarations }
    constructor Create(AOwner: TComponent);override;
    destructor Destroy;override;
  published
    { Published declarations }
    property Button: TButton read fButton write fButton;
    property ListBox: TListBox read fListBox write fListBox;
  end;

procedure Register;

implementation


destructor TExtPanel1.Destroy;
begin
 fButton.Free;
 fListBox.Free;
 inherited Destroy;
end;

constructor TExtPanel1.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
 ControlStyle := ControlStyle - [csSetCaption];
 Caption:= '';
 Width:= 200;
 Height:= 100;
 fButton:= TButton.Create(Self);
 fButton.Parent:= Self;
 fButton.Left:= 10;
 fButton.Top:= 10;
 fButton.Caption:= '';

 fListBox:= TListBox.Create(Self);
 fListBox.Parent:= Self;
 fListBox.Left:= 10;
 fListBox.Top:= 50;

end;

procedure Register;
begin
  RegisterComponents('Samples', [TExtPanel1]);
end;

end.
0

Featured Post

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

771 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