• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Compound Component

Hi experts,

I would like to make a component that consists of

Label followed by an Edit and over that edit a button - at the end of the edit-. i want to have all the events of the edit contrtols and the buttom control.

any one knows how to make so.
0
aliahmedali
Asked:
aliahmedali
1 Solution
 
kretzschmarCommented:
>any one knows how to make so.

yes ;-)

sample may follow tomorrow
0
 
nestoruaCommented:
HI,
Yes, too ;)
First possibility - using frames.
Second - you could look at the VCL source and see how DELPHI did it with TLabeledEdit component. It is almost what you wish to create.
Sincerely,
Nestorua.
0
 
the_edgeCommented:
A,

This is indeed possible. The easiest way to do this is with the help for frames. I enclose here all you need to get this going:

1.  Create a new frame unit and save it as u1.pas
2. Create a new package and name it package1.dpk

3. Place the following code into the requires / contains clauses in the DPK file:

requires
  rtl,
  vcl;

contains
  u1 in 'u1.pas' {fraSample: TFrame};

4. In the frame you created:

4.1 Change its property Name to --> fraSample
4.2 Drop a single TButton onto it
4.3 Drop a single TEdit ontrol it

Replace the contents of u1 with the following code:

unit u1;

interface

uses
  Windows,
  Messages,
  SysUtils,
  Classes,
  Graphics,
  Controls,
  Forms,
  Dialogs,
  ExtCtrls,
  StdCtrls;

type
  TfraSample = class(TFrame)
    Edit1: TEdit;
    Button1: TButton;
  published
    property EditControl: TEdit read Edit1;
    property ButtonControl: TButton read Button1;
  end;

type
  TMyPanel = class(TCustomPanel)
  private
    FGUI: TfraSample;
  protected
    procedure Loaded; override;
  public
    constructor Create(AOwner: TComponent); override;
  published
     property GUI : TfraSample read FGUI;
  end;

procedure Register;

implementation

procedure Register;
begin
    RegisterComponents('EE', [TMyPanel]);
end;

{$R *.dfm}

constructor TMyPanel.Create(AOwner: TComponent);
begin
  inherited;

  //Create the GUI we will be exposing and embed into ourselves
  FGUI := TfraSample.Create(Self);
  FGUI.Parent := Self;
  FGUI.Align := alClient;
  //This is not strictly necessary as it should already be shown as a
  //sub component, but do it anyway
  FGUI.SetSubComponent(TRUE);
  //Expose the events we want from the controls on the frame
  FGUI.Edit1.SetSubComponent(TRUE);
end;

procedure TMyPanel.Loaded;
begin
  inherited;

  //Give our embedded component a unique name once the properties have
  //streamed in
  FGUI.Name := Self.Name + '_GUI';
end;

end.

5.1 Build Package1
5.2 Install Package1

Now look on the EE tab and you will have the component you just created. As you can see the properties and events as specified in the TMyPanel.Create() constructor are there for you to use.

If anything is unclear give me a yell.


0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
aliahmedaliAuthor Commented:
hi all, thanx the_edge but I dont want to show the frame under the label, edit and button I would their to appear as if i dropped each on on the form solement.

any ideas?
0
 
the_edgeCommented:
A,

OK that is easier. See this code below. Place this into a package and compile. As soon as you drop the component onto a form you will see an edit and button created. As the components are owned by the form you can delete the component you just dropped and they will persist. Obviously heaps of permiutations on this, but this should get you going.


type
  TMyComponent = class(TComponent)
  public
    constructor Create(AOwner: TComponent); override;
  end;

procedure Register;

implementation

procedure Register;
begin
  //RegisterComponents('EE', [TMyPanel]);
  RegisterComponents('EE', [TMyComponent]);

end;

{$R *.dfm}

constructor TMyComponent.Create(AOwner: TComponent);
var
  pfForm            : TForm;
begin
  inherited;

  //We _assume_ we are being dropped on a form
  pfForm := (Self.Owner as TForm);

  //Place edit box on the form
  with TEdit.Create(pfForm) do
  begin
    Left := 10;
    Width := 40;
    Top := 10;
    Text := 'My Edit';
    Parent := pfForm;
    //Crude way for unique naming
    Name := 'ME' + IntToStr(GetTickCount);
  end;

  //Place button on the form
  with TButton.Create(pfForm) do
  begin
    Left := 60;
    Width := 40;
    Top := 10;
    Caption := 'My Button';
    Parent := pfForm;
    //Crude way for unique naming
    Name := 'MB' + IntToStr(GetTickCount);
  end;
end;
0
 
kretzschmarCommented:
just had no time

but see my answer at q
http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_20699349.html

this shows how it could be done

meikl ;-)
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now