?
Solved

Creating component

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

862 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