Board index » delphi » Dropping a component onto a form programaticly: Help!

Dropping a component onto a form programaticly: Help!

Here's what i want to do:

I've made a ComponentEditor to add a menu item called "Label" to the
context menu of a TTable component.  When the "Label" item is selected
i want the ComponentEditor to drop a TLabel onto the form with the
Table's file name as the caption.

My question is: How can I get the ComponentEditor to drop the TLabel
onto the form -- from my ComponentEditor's ExecuteVerb() method.

Is this possible?  Is there an API function that will drop components
at design time?

Thanks,
Bill.

 

Re:Dropping a component onto a form programaticly: Help!


Quote
Bill Friedrich wrote:

> Here's what i want to do:

> I've made a ComponentEditor to add a menu item called "Label" to the
> context menu of a TTable component.  When the "Label" item is selected
> i want the ComponentEditor to drop a TLabel onto the form with the
> Table's file name as the caption.

> My question is: How can I get the ComponentEditor to drop the TLabel
> onto the form -- from my ComponentEditor's ExecuteVerb() method.

> Is this possible?  Is there an API function that will drop components
> at design time?

> Thanks,
> Bill.

In your event code, add:

mylabel := tlabel.create(self);
mylabel.parent := self;
... set any properties you want ...

Remember to add a the variable "mylabel : tlabel" somewhere with the
appropriate scope. (Just above the form declaration would be good.)

Also, remember to call mylabel.free when you no longer need the label.

Hope it works.

Mitch

Re:Dropping a component onto a form programaticly: Help!


It'easy.
first create the component with it's create method.
then add the component to the form with the forms 'insertcontrol' method.
It is then listed in the 'Form.Controls' array, and it will be controlled
and closed by the form.

here's an example:

(put this in a Form.ButtonClick method.)

var t:TMyControl;
begin
t:=TMyControl.create(self);
with t do
     begin

     Some property assignments

     end;
InsertControl(t);

Bill Friedrich <frie...@interactive.net> schreef in artikel
<32e7fc52.3044...@news.interactive.net>...

Quote
> Here's what i want to do:

> I've made a ComponentEditor to add a menu item called "Label" to the
> context menu of a TTable component.  When the "Label" item is selected
> i want the ComponentEditor to drop a TLabel onto the form with the
> Table's file name as the caption.

> My question is: How can I get the ComponentEditor to drop the TLabel
> onto the form -- from my ComponentEditor's ExecuteVerb() method.

> Is this possible?  Is there an API function that will drop components
> at design time?

> Thanks,
> Bill.

Other Threads