How to add or remove controls on the fly?

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

Post Reply
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

How to add or remove controls on the fly?

Post 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
With best regards,
Sudip
User avatar
Rathinagiri
Posts: 5482
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Contact:

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

Post 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()
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

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

Post by sudip »

Thanks a lot friend :D
I should have checked it :oops:
With best regards.
Sudip
With best regards,
Sudip
User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

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

Post 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).
Ricci
Posts: 255
Joined: Thu Nov 19, 2009 2:23 pm

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

Post 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

User avatar
Alex Gustow
Posts: 290
Joined: Thu Dec 04, 2008 1:05 pm
Location: Yekaterinburg, Russia
Contact:

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

Post 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.
Post Reply