[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

dynamic creation of a component within a component

Posted on 2002-07-10
9
Medium Priority
?
294 Views
Last Modified: 2010-04-04
I've been trying to place components on a form dynamically and have got as far as the code below successfully.

What I now need to do is create the same as below BUT with a linked TUpDown control.

What I can't work out is

how to create it and more to the point link it up.

I know that I need to create the component somewhere within this procedure but I can't see where to use the TUpDown.associate property.

Note this is just code in a unit - I'm not particularly trying to create a component although that may be the way to go.

TVMIA

John


procedure DynaIBEdit(form: Tform; myparent: Twincontrol; mytop, myleft, mywidth: integer; myds: TIB_datasource; mydf:
  string);
begin
  with TIB_edit.Create(form) do begin
    parent := myparent;
    top := mytop;
    left := myleft;
    width := mywidth;
    DataSource := myds;
    datafield := mydf;
end;
0
Comment
Question by:jbeh
  • 4
  • 4
9 Comments
 
LVL 6

Accepted Solution

by:
DrDelphi earned 400 total points
ID: 7144450
procedure DynaIBEdit(form: Tform; myparent: Twincontrol; mytop, myleft, mywidth: integer; myds: TIB_datasource; mydf:
 string);
 var UpDown:TupDown;
     TibEdit:Tib_edit;
 begin
   TibEdit:=TIB_edit.Create(form);
   with TibEdit do
   begin
     parent := myparent;
     top := mytop;
     left := myleft;
     width := mywidth;
     DataSource := myds;
     datafield := mydf;
   end;
   UpDown:=TUpDown.create(self);
   with UpDown do
   begin
     Parent:=TibEdit;
     Left:=TibEdit.width-10;///default to 10 pixels wide;
     top:=0;
     height:=TibEdit.height;
     OnClick:=ClickEventHandler; /// this is a routine you design to handle
                                 // the click event
   end;
 end;

0
 

Author Comment

by:jbeh
ID: 7145304
Unfortunately I am not quite getting the effect I am trying to acheive.


If I put the components on a form at design time as follows

    inherited Ts_Edit: TTabSheet
      object IB_Edit1: TIB_Edit
        Left = 584
        Top = 44
        Width = 109
        Height = 21
        DataField = 'probability_of_getting'
        DataSource = IB_DataSource_base
        TabOrder = 1
      end
      object UpDown1: TUpDown
        Left = 693
        Top = 44
        Width = 12
        Height = 21
        Associate = IB_Edit1
        Min = 0
        Increment = 5
        Position = 0
        TabOrder = 2
        Wrap = False
        OnClick = UpDown1Click
      end
    end


I get the functionality I need which amounts to a data aware spinner control (used for forcing integers between 0 and 100) without needing to write any events at all.

What I currently have is

procedure DynaIBspinEdit(form: Tform; myparent: Twincontrol; mytop, myleft, mywidth: integer; myds: TIB_datasource; mydf:
  string);
var
  UpDown                      : TupDown;
  TibEdit                     : Tib_edit;
begin
  TibEdit := TIB_edit.Create(form);
  with TibEdit do begin
    parent := myparent;
    top := mytop;
    left := myleft;
    width := mywidth;
    DataSource := myds;
    datafield := mydf;
  end;
  UpDown := TUpDown.create(form);
  with UpDown do begin
    Parent := tibedit;
    ArrowKeys := true;
    min := 0;
    max := 100;
    increment := 5;
    position := 0;
    OnClick := UpDown.OnClick;
    Associate := tibedit;
  end;
end;

I'm wondering if I've got a parenting issue

  UpDown := TUpDown.create(self); fails - Undeclared identifier self.


Anyway - I am very close but I'm not quite there yet..


John



0
 
LVL 17

Expert Comment

by:geobul
ID: 7145526
Hi,
I think that UpDown.Parent should be the same as TibEdit.Parent.

Regards, Geo
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 17

Expert Comment

by:geobul
ID: 7145538
Also:
OnClick := UpDown.OnClick;
seems to be wrong.
0
 

Author Comment

by:jbeh
ID: 7145695
Geo

Hi - I'll make the changes although I think when I was playing last night I tried this to no avail.

I'll have another go anyway

Ta

John
0
 
LVL 17

Expert Comment

by:geobul
ID: 7145727
The following work fine I think (I've used TEdit):

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure DynaIBspinEdit(form: Tform; myparent: Twincontrol; mytop, myleft, mywidth: integer);
    procedure UDClick(Sender: TObject; Button: TUDBtnType);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.DynaIBspinEdit(form: Tform; myparent: Twincontrol; mytop, myleft, mywidth: integer);
var
 UpDown                      : TupDown;
 TibEdit                     : Tedit;
begin
 TibEdit := TEdit.Create(form);
 with TibEdit do begin
   parent := myparent;
   top := mytop;
   left := myleft;
   width := mywidth;
//   DataSource := myds;
//   datafield := mydf;
 end;
 UpDown := TUpDown.create(form);
 with UpDown do begin
   Parent := myparent;
   ArrowKeys := true;
   min := 0;
   max := 100;
   increment := 5;
   position := 0;
   OnClick := UDClick;
   Associate := tibedit;
 end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  DynaIBspinEdit(Form1, Form1, 50, 50 ,100);
end;

procedure TForm1.UDClick(Sender: TObject; Button: TUDBtnType);
begin
  ShowMessage('UpDown was clicked');
end;

Regards, Geo
0
 

Author Comment

by:jbeh
ID: 7152121
Thank you Gents.

I have now got this working satisfactorily with the following code

procedure DynaIBspinEdit(form: Tform; myparent: Twincontrol; mytop, myleft, mywidth: integer; myds: TIB_datasource; mydf:
  string);
var
  UpDown                      : TupDown;
  TibEdit                     : Tib_edit;
begin
  TibEdit := TIB_edit.Create(form);
  with TibEdit do begin
    parent := myparent;
    top := mytop;
    left := myleft;
    width := mywidth;
    autolabel.kind := albleft;
    autolabel.Options := [{albdotleader,} albonlyfirstcharupper, albboldifrequired {, albsuffixbeforedots}];
    autolabel.Suffix := ' :--';
    DataSource := myds;
    datafield := mydf;
 end;
  UpDown := TUpDown.create(form);
  with UpDown do begin
    Parent := myparent;
    ArrowKeys := true;
    min := 0;
    max := 100;
    increment := 5;
    position := 0;
    wrap := true;
    OnClick := OnClick;
    Associate := tibedit;
  end;
end;

I think part of my problem is that I had similar designed control for comparison purposes and things didn't work until I dumped it.  

Truly don't understand why but there you go. :-)


I am NOT 100% sure why this has taken me so long but as I have now got it sorted I can start making progress again.

Thank you both very much.

All other things being equal I'll close this question tomorrow and pay my dues


0
 

Author Comment

by:jbeh
ID: 7153721
Thanks all

John
0
 
LVL 17

Expert Comment

by:geobul
ID: 7153740
I must say that your choice is not fair and will mislead people who will buy this question to use wrong code.

Regards, Geo
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month20 days, 8 hours left to enroll

867 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