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

Creating component

Posted on 2004-03-30
3
155 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
  • 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 80 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Suggested Solutions

Title # Comments Views Activity
creating threads in delphi 1 130
SUM 2 INTEGER ARRAYS INTO 1 10 108
Not able to call Delphi XE10 dll function from Delphi 6.0 4 37
enhance the following code 3 37
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

789 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