Page 1 of 1

How to add or remove controls on the fly?

Posted: Mon Dec 14, 2009 2:18 pm
by sudip
Hello All,

How to add or remove controls in a window on the fly?
May be it's very elementary or it was already discussed in the forum. In that case please send the url of the discussion.
Thanks in advance.
With best regards.

Sudip

Re: How to add or remove controls on the fly?

Posted: Mon Dec 14, 2009 5:23 pm
by Rathinagiri
It is very easy to add/remove a control once the window is active.

Either add "OF" or "PARENT" keyword to the definition.

For example,

Code: Select all


define button button_1
   row 100
   col 100
   parent form_1
   caption "New Button"
   action msginfo("You have pressed the new button!")
end button

The above code should create a new button on the fly.

Suppose you want to remove a particular control, give the following command.

Code: Select all

Form_1.Button_1.release()

Re: How to add or remove controls on the fly?

Posted: Tue Dec 15, 2009 4:17 am
by sudip
Thanks a lot friend :D
I should have checked it :oops:
With best regards.
Sudip

Re: How to add or remove controls on the fly?

Posted: Tue Dec 15, 2009 5:11 am
by Alex Gustow
Yes - I'm using this technique in my apps often (in one situation I need one group of controls, in another - another group etc.) It's very easy and useful trick.

For example - I use it when I create controls in "auto-zoom'ed" apps (I wrote about this some time ago): I define main window in Main() function, and define controls into this window only after initialization of main window (in function called from ON INIT clause).

Re: How to add or remove controls on the fly?

Posted: Wed Dec 16, 2009 4:19 pm
by Ricci
Alex Gustow wrote:Yes - I'm using this technique in my apps often (in one situation I need one group of controls, in another - another group etc.) It's very easy and useful trick.

For example - I use it when I create controls in "auto-zoom'ed" apps (I wrote about this some time ago): I define main window in Main() function, and define controls into this window only after initialization of main window (in function called from ON INIT clause).
And it´s the only way to define controls when you don´t know if or how many you will need during runtime.
Then you can work with the &-operator to define:

Code: Select all


FOR nPos := 1 TO xx                         // xx was calculated during runtime
	 @   10, 20*nPos ;
	 	LABEL &("LabelY" + STR( nPos, 4, 0 ) ) ;
		PARENT Form_5 ;
		VALUE STR( nPos, 2 ) ;
		WIDTH 20 HEIGHT 10 ;
		FONT "ARIAL" SIZE 07 
NEXT


Re: How to add or remove controls on the fly?

Posted: Thu Dec 17, 2009 8:19 am
by Alex Gustow
Ricci wrote:Then you can work with the &-operator to define:
Yes - I use exactly this way very often in such cases.