Solved

Compound Component

Posted on 2003-10-27
6
218 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
[X]
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
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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

Technology Partners: 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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month4 days, 21 hours left to enroll

636 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