Solved

Creating component

Posted on 2004-03-30
3
153 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
Comment Utility


 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
Comment Utility
Yes it is possible to create compound objects?

Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 80 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

744 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now