How Do I Initialize My Application? (Magic xpa 4.x)
When you are setting up an application, there will be items you want to set up globally, before any of your programs run, and use in many programs. In Magic xpa, these items are kept in the Main Program, which is a special program at the top of the Program repository.
You can think of the Main Program as being the “parent” task of any program in the project. The Task Prefix runs before your program runs, even when you are just testing in Debug mode. You have access to any function or variable in the Main Program while your program runs. And when the project is closed, Task Suffix of the Main Program runs (or after you are finished testing your program in Debug mode).
In the Data View section of the Main Program, you can put variables that will be used throughout the application, including OLE objects. You can initialize these variables in Task Prefix.
If you have an application that uses one type of variable a lot, such as a BLOB that is used for SOAP services, the Main Program’s Data View can be a handy place to keep that variable.
-
In Task Prefix, put the operations you want to have execute before any programs run. Here, we have operations to initialize tables, by moving data from saved BLOB files into Magic xpa tables. You can also call programs here, for instance, to track user logins.
-
In Task Suffix, put the operations you want to have execute when the user is exiting the project. In this example we store the data from the tables back into BLOBs. Again, you can call programs here to perform various tasks.
-
You can also enter Function logic units. Any functions you enter here will be globally available, and will show up on the Magic xpa function list.
-
Event logic units will be globally available if entered here. In our example, we have set Ctrl+S to call a Spell Checker for whatever field the user happens to be on. Doing this sort of logic in the Main Program means you don’t have to do it multiple times in the individual programs.
You can also use Event logic units to globally trap errors, using the Error type events.
-
Variable Change logic units can be used to give messages or do logging.