Solved

Compound Component

Posted on 2003-10-27
6
217 Views
Last Modified: 2010-04-05
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
Comment
Question by:aliahmedali
6 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9628921
>any one knows how to make so.

yes ;-)

sample may follow tomorrow
0
 
LVL 4

Expert Comment

by:nestorua
ID: 9629087
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
 

Expert Comment

by:the_edge
ID: 9632647
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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:aliahmedali
ID: 9637600
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
 

Accepted Solution

by:
the_edge earned 150 total points
ID: 9640151
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
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9640207
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Delphi XE10, MySQL Query 4 167
Communication Between RC4 Delphi <-> PHP 3 123
FMX enumerated colours 2 118
DBCtrlGrid, Delphi, Scroll 8 38
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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 a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
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…

830 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