Announcements
Hi,
At run time, I'm trying to generate a simple popup form that displays an image. the image is stored as a Base64 string and converted to an Image object OK. I then generate a new form at run-time, which is also fine, but I can't get the syntax right to add the image to the form. I've not created a form at run time before, so it could be that I'm not adding controls to it properly...
Looking through the available methods on FormControls, I thought the FormImageControl or FormWindowControl classes would be fairly straight forward - but curiously, I can't seem to instantiate a FormImageControl or a FormWindowControl.
- When declaring a FormImageControl variable in my method, the compiler doesn't recognize the class type (error: "variable FormImageControl has not been declared").
- And while I can declare a FormWindowControl variable, I can't instantiate it in the normal way, as type 'Window' doesn't appear in the FormControlTypes Enum.
The MSDN documentation doesn't acknowledge any of these quirks, implying that these two children of FormControl behave the same as the others. Here's my code (various attempts are commented out but hopefully you get the picture:
void button_clicked(formButtonControl _formButtonControl)
{
Args args;
Form windowForm;
FormRun formRun;
FormBuildDesign formBuildDesign;
FormBuildControl formBuildControl;
str imageBase64;
BinData binData = new BinData();
container baseContainer;
Image image;
FormWindowControl windowControl;
FormImageControl imageControl; // variable FormImageControl has not been declared???
// Create container from base64
baseContainer = BinData::loadFromBase64("imageBase64String here");
// Create binData from container.
binData = new BinData();
binData.setData(baseContainer);
// lock element
element.lock();
// create Image from binData
image = new Image();
image.setData(binData.getData());
// Create the form to display the screenshot
windowForm = new Form();
// Create the form design.
formBuildDesign = windowForm.addDesign("Design");
formBuildDesign.caption("Caption here");
formBuildDesign.height(image.height());
formBuildDesign.width(image.width());
formBuildDesign.style(3);
//
// Problem Adding/Displaying the image!
// Obviously simple to do with embedded resources but not obvious from binData Image object
//
// Approach 1: FormImageControl
imageControl = windowForm.addControl(FormControlType::Image, "Image");
imageControl.image(image);
// Approach 2: FormWindowControl
windowControl = windowForm.addControl(FormControlType::Window, "Window"); // Enum element not found!
windowControl.image(image);
// Create the run-time form.
args = new Args();
args.object(windowForm);
formRun = classfactory.formRunClass(args);
formRun.run();
formRun.detach();
}
*This post is locked for comments
Hi TTr2,
You got error about design because you had no design :) Please refer to this msdn example msdn.microsoft.com/.../aa867829.aspx
As you can see there you need to create a form then add new design:
// Create the form design.
formBuildDesign = form.addDesign("Design");
Hi Ievgen - I've fixed it by fully instantiating the formRun commands before adding controls. Phew! Thanks for your help, I'll mark your answer as correct.
So:
// Create the form to display the screenshot
windowForm = new Form();
args = new Args();
args.object(windowForm);
formRun = classfactory.formRunClass(args);
formRun.run();
formRun.detach();
// Then add controls
windowGroup = formRun.design().controlName("Window Group");
windowGroup = formRun.design().addControl(FormControlType::Group, "Window Group");
windowGroupInner = formRun.design().controlName("Inner Window Group");
windowGroupInner = windowGroup.addControl(FormControlType::Group, "Inner Window Group");
windowControl = formRun.design().controlName("Screenshot");
windowControl = windowGroupInner.addControl(FormControlType::Image, "Screenshot");
windowControl.image(image);
Hi Ievgen,
Thanks for the tips. I didn't know about cross referencing, very helpful. I've copied the \Classes\DirParty\showHideMessageBar() example, which utilizes your advice about instantiating a FormWindowControl object as a FormControlType::Image (it doesn't make sense to me but I'm going with it).
However, I am having trouble adding any controls to the new form, the error is that the formRun.design() variable/property is not initialized. So assuming that you have solved the FormWindowControl instantiation, please could you help me with instantiating my run time form? The form does create a small window provided that no controls are added to it.
I suspect that there is a lot of 'magic' happening under the hood when you create forms in the AOT that is not being called when I do the following (assuming all variables are declared above) :
void ViewImageButtonControl_clicked(FormButtonControl _formButtonControl)
{
Args args;
Form windowForm;
FormRun formRun;
FormBuildDesign formBuildDesign;
str imageBase64;
BinData binData = new BinData();
container baseContainer;
Image image;
FormWindowControl windowControl;
FormGroupControl windowGroup, windowGroupInner;
;
// Create container from base64
imageBase64 = "BASE64STRINGHERE";
baseContainer = BinData::loadFromBase64(imageBase64);
// Create binData from container.
binData = new BinData();
binData.setData(baseContainer);
// lock element
element.lock();
// create Image from binData
image = new Image();
image.setData(binData.getData());
// Create the form to display the screenshot
windowForm = new Form();
// Create the run-time form.
args = new Args();
args.object(windowForm);
formRun = classfactory.formRunClass(args);
// Add an image control to the popup form and display image
windowGroup = formRun.design().controlName("Window Group");
windowGroup = formRun.design().addControl(FormControlType::Group, "Window Group");
windowGroupInner = formRun.design().controlName("Inner Window Group");
windowGroupInner = windowGroup.addControl(FormControlType::Group, "Inner Window Group");
windowControl = formRun.design().controlName("Screenshot");
windowControl = windowGroupInner.addControl(FormControlType::Image, "Screenshot");
windowControl.image(image);
formRun.run();
formRun.detach();
}
Thanks!
Hi TTr2,
Try FormControlType::Image for WindowControl. To set image use "imgae" property.
WindowControl.image(image);
You can find couple of eexmaples if you will use crossreferences by FormControlType::Image enum (could be found under systemDocumentation node in AOT)
André Arnaud de Cal...
293,296
Super User 2025 Season 1
Martin Dráb
232,093
Most Valuable Professional
nmaenpaa
101,156
Moderator