Add Control at Runtime in IDE Env

Moderator: Rathinagiri

Post Reply
melliott42
Posts: 119
Joined: Wed Feb 18, 2009 2:14 pm

Add Control at Runtime in IDE Env

Post by melliott42 » Mon Mar 28, 2016 2:43 pm

Hello,

I am trying to move to use the IDE as my primary method to create apps in HMG. I am having an issue with adding a control (a button for example) to my main window that is not defined using the IDE. I am using the standard DEFINE BUTTON syntax but when running it keeps coming up with an error or simply does not show.

I tried using Main.btnTest2.Show and other methods to get it to show but no success. I know this must be something simple.

So basically I am asking for the baby steps on how to add a new button programmatically and yet still use the IDE?

EDIT: Maybe I am simply placing the code in the wrong place or need to "turn it on" after defined in a particular place.


Thanks,

Michael

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Mon Mar 28, 2016 2:56 pm

Can you please provide your sample project files?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

melliott42
Posts: 119
Joined: Wed Feb 18, 2009 2:14 pm

Post by melliott42 » Mon Mar 28, 2016 4:15 pm

Can you please provide your sample project files?
I am basically trying to create a new project to model how to do this so not yet but here is what I have done:

* Create a directory for a new Project \IDE2Code1
* Created and new project in the created dir.
* Added one button to the project main frm\window via the IDE GUI (btnTest1).
* Run project to ensure everything works. It does up to this point as expected.

Next I want to add a button (btnTest2) to the main window programmatically. I have used the standard DEFINE BUTTON syntax shown in the docs and examples. I am not sure where (in this IDE initiated\managed code) to place to the code to have it create and show the button at the same time my IDE created button shows. Yes I am aware the main.fmg files are basically HMG (these are statically defined though, i.e. not in real-time).

I have had no issues creating controls using the IDE and assigning functions to the corresponding actions. This I can do without any issues. It is adding controls in real-time that I am having an issue. I think it is a matter of me understanding where I need to put the code and how\where to put the function to activate\show it in an IDE managed project.

EDIT: For instance I tried adding the code after the standard: Load Window Main = Did not work etc.

I hope this makes what I have done and my objective clearer.

What can you recommend?

Thanks,

Michael

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Mon Mar 28, 2016 4:57 pm

As you have said, it is simple. Let me show you.

Double Click on the '+' as shown below, to add a module to main form init event.
001.jpg
001.jpg (37.81 KiB) Viewed 2307 times
002.jpg
002.jpg (9.22 KiB) Viewed 2307 times
003.jpg
003.jpg (27.6 KiB) Viewed 2276 times
004.jpg
004.jpg (9.33 KiB) Viewed 2307 times
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

melliott42
Posts: 119
Joined: Wed Feb 18, 2009 2:14 pm

Post by melliott42 » Mon Mar 28, 2016 5:27 pm

Rathinagiri perfect its now working!

What I think I missed was:
1. I needed to "Create a New Function Module" on the OnInit() event of the main window.
2. Put the code in the corresponding new .prg as you indicated.

EDIT: I think I was close adding code in different events but perhaps the IDE needed to initiate\manage it as you indicated. I hope that helps anyone else having the same issue.

Thank you so much for your help!

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Mon Mar 28, 2016 6:54 pm

I am happy hat it worked.

Since GUI is event driven, we have to write the code to the appropriate event as a module. It can be inside the same prg or by a new prg as created by IDE on double clicking the '+' sign.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

Post Reply