MultipleWindows_preview.jpg

Using multiple forms in a project

The first thing you should know about forms in PPL is that they are auto-converted to a .ppl file at compile time and if you don't specify the form is a library type form PPL will generate code to create and display the form within a WinMain function. This is perfectly fine for a single form project but in a multi-form project it will cause the compiler to give you an error that you have duplicate WinMain functions.

The solution is very simple. First you need to make sure that your non-main forms will be generated as library type forms, to do this in the PIDE, go to Form -> Form Options -> Generate Library and make sure this menu item is checked. For this example we will save our form file to MyForm.frm. At compile time PPL will generate a new MyForm.ppl file and it will create a new function called Form100Create () instead of a WinMain. Notice that our form name needs to be Form100.

You will now need to include this .ppl file in the code or form you want to call this new form from. A simple #include "myform" will do the trick. Now where to place it you ask? The Initialization section code is the best place, go to Form -> Initialization section code and add the following line:

#include "myform"

Once the form file is included in your main form, it is time to create Form100 in memory and display it. In your code where you want to do this, you will need to do the following:

f$ = Form100Create;
Form_Show (f$);

Once you don't need the form anymore, this could be done in the MyForm code, you need to destroy the form from memory by doing the following:

Form_Close (f$);
Form_Destroy (f$);

Make sure f$ is valid. You will probably need to call this code from another form. Just closing the form won't destroy it from memory.

If you want MyForm to be a dialog box type form, in the PIDE, make sure Form -> Form Options -> Dialog Form is also checked. This will make the form a special dialog box type form when created. Your calling code will look something like this:

f$ = Form100Create;
if (ShowModal (f$, NULL, false) == 1)
// do some code here
end;
Form_Destroy (f$);

The ShowModal() function takes three parameters. The first one is the form handle of the dialog to show, the second is the control to set the focus on when the dialog is shown, this value can be left to NULL, the first control that can get focus will get it and finally the last parameter is whether you want the dialog to be fullscreen or not on the PocketPC, this last value is generally false.

How do I set buttons to close my dialog form and return a specific value?

PPL offers a very easy way to do this. The trick is in the ID of the button. If you want to create an OK button, set the button ID to a value of 1. To create a Cancel button, set the ID to a value 2. All buttons with an ID less than a value of 100 will close the dialog form and return the ID has a result to the ShowModal() function. This way you are not limited and can create up to 99 buttons that can close a dialog form and each return a specific value. You can create Ignore, Retry, Yes To All, No To All buttons with ease.