Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding form objects at runtime

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hi all

I would like to be able to add textboxes, labels etc to a form at runtime, the method to be called from the Load event.

How can one do this?

TIA

SparePart
 
thisform.addObject("cmd","CommandButton")
thisform.cmd.visible=.T.

You should note when you add objects in this way you have to reset all the values. If you know basically what general types of controls you want to add you could pre-define them and still add them at run time.

in your program for example...
DEFINE CLASS MyCheckBox AS CHECKBOX
visible = .T. && .F. is default
left = 10
top = 10
Procedure Click
RETURN
ENDPROC
ENDDEFINE [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
Thanks Pete

THISFORM.AddObject([cmdClose],[COMMANDBUTTON])
WITH THISFORM.cmdClose
[tab].Height = 25
[tab].Width = 56
[tab].Caption = [Close]
ENDWITH

Can I add a click() method to the class just added or do you have to define the class up front?

SparePart
 
So far as I know you have to add the click methods when you define the class... not at run time.

for example...

DEFINE CLASS MyCheckBox AS CHECKBOX
visible = .T. && .F. is default
left = 10
top = 10
Procedure Click
RETURN
ENDPROC

ENDDEFINE

Something is nagging me in the back of my head about this. But I have never tried to add commands at run time before. There is macro substitution... but I don't think this would work for you here. Assuming they are several circumstances your class needs to react to, you may need to write a smarter class with many options to react to the varying conditions. [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
You can read method code from objects at runtime, but you cannot write method code at runtime. I had a need for this, too, as I had wanted a generic grid, and put in DoubleClick code dynamically depending on the RecordSource for the grid. Darn. [sig]<p>Robert Bradley<br><a href=mailto: > </a><br><a href= - Visual FoxPro Development</a><br> [/sig]
 
Thanks all

DEFINE CLASS cmdClose AS COMMANDBUTTON
[tab]Caption = [Close]
[tab]Height = 25
[tab]Width = 56
[tab]Procedure Click
[tab][tab]THISFORM.Release
[tab]ENDPROC
ENDDEFINE

What happens next?

THISFORM.AddObject(?,?)?

TIA

SparePart
 
In the form's init event...

thisForm.AddObject(&quot;oClose&quot;,&quot;cmdClose&quot;)

In one of your project procedure files you want to add in the class definition. It seems a bit clumsy the first time. But I think you will see it is a powerfull way to solve problems and likely you will use it more and more. I write most all my grids from scratch. That way your have total control. And don't have to mess with the builder or the form designer. [sig]<p> Pete<br><a href=mailto:blindpete@mail.com>blindpete@mail.com</a><br><a href= > </a><br>What your mother told you is true! You will go blind! (from moonshine anyway)[/sig]
 
You can read method code from objects at runtime, but you cannot write method code at runtime. I had a need for this, too, as I had wanted a generic grid, and put in DoubleClick code dynamically depending on the RecordSource for the grid. Darn.

Robert, remember you can add ANY class in run-time? Make your own class for grid column control(s). Put &quot;this/parent.parent.eventDoubleClick()&quot; in the DblClick event of control(s). Than add custom method to grid (eventDoubleClick), that will be called from controls. Thats all. When grid rebuilt by VFP, however, you will need to add custom controls again.
I did made excellent grid class with many features and never had a problem like 'adding of method code in run-time', except for column events. However, I do not need column events, because any action that cause column event also cause events somewhere else (header/grid), that may be used too.
[sig]<p>Vlad Grynchyshyn<br><a href=mailto:vgryn@softserve.lviv.ua>vgryn@softserve.lviv.ua</a><br>[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top