Home Forums General XMetaL Discussion Customization object? How can I use a form? Reply To: Customization object? How can I use a form?

Derek Read

Reply to: Customization object? How can I use a form?

Still guessing a bit but here's an example that might help.

There's an example macro in the Journalist.mcr file called “Insert ULink” that launches a form, lets the user input a Description and URL, and then generates some content in the XML based on that input.

My sample below reuses that form but doesn't tie it to a document (in the original it isn't tied to any document either really, it's just that the Journalist sample is the only one to use it). Instead of inserting the values into the document like the Journalist sample does this sample merely checks the values and displays them.

Not sure what you want to do with your values, but in this example they are now strings and you can do whatever you like with them.

//XMetaL Script Language JScript:
var formPath = Application.Path + “\Forms\ULink.xft”;
var dlg = Application.CreateFormDlg(formPath);

//as long as you don't set the form object to null
//(in this example that's “dlg”)
//you can access the controls on it like so:
if (dlg.DoModal == 1) { //user clicked OK button*
var desc = dlg.URLDesc.Text;
var url = dlg.URLLink.Text;
Application.Alert(“Description: ” + desc + “n” + “URL: ” + url);
dlg = null;

*For a form to return 1 when an OK button is pressed you need to set ButtonType for the button to “OK” (as in this form).
When the user dismisses a dialog using the built-in close button on a form -1 is returned.
When the user dismisses a form using a button with ButtonType set to “Cancel” then 2 is returned.

You should null any references to the form eventually (before XMetaL shuts down, but the safest place is in the same script that launched the form so you know for sure the reference is gone). Windows Script Host (JScript and VBScript) does do garbage collection but the timing is not predictable. XFT's are running as part of an external control (a COM DLL) and COM references need to be cleaned up to make sure the software can properly shut down.