[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Creating component

Posted on 2004-03-30
3
Medium Priority
?
162 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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…
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…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

656 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