Problem when creating a dynamic form with ActiveX control & Solution :)

The Requirement was to connect to the web
and get the content of the web page and display it on

the form .Well, I did not want to create a
form in AOT to display the HTML content .So , I thought of dynamically creating
a form and adding the browser ActiveX Control using X++ code.

Here is the code which I pasted in the job.

 static void ActiveX_DynamicForm(Args _args)


    COMDispFunction         webpreviewWrite;

    COMVariant                  text = new COMVariant();

COM                              ctrl = new COM();

Form                               formBrowse;

FormActivexControl    activex;

FormRun                       formRun;

Args                              args;

int                                  handle;

WinInet                        wi =
new WinInet();

str                                  htmlContent;


= wi.internetOpenUrl(‘’);



htmlContent = wi.internetReadFile(handle);




formBrowse = new Form(‘ActiveX AX Form’, true);;;, ‘Browser’);

    args =
new Args(;;


formRun = classFactory.formRunClass(args);


activex =‘Browser’);





webpreviewWrite = new COMDispFunction(ctrl, ‘write’,




I was successful in creating the form but
strangely AX threw me an error when I ran the code. It was not supporting ‘write’ method for automatic interface
of COM object of class “IWEBBrowser2’

I did not want to create a separate form adding
an ActiveX control to achieve this.

I looked for alternatives and found one interesting
class which served my purpose.

Class Name: KMKnowledgeFunctionShow

Method : static Object show(TextBuffer   
htmlText,     Object        _formRun = null)

The show method will open the standard “KMKnowledgeAnalogMeter”
form which has an ActiveX Control added to it.

I got the content of the webpage and added it
to the TextBuffer by using settext() method and passed the TextBuffer to the
show method. I did not pass the second parameter formrun.

The idea behind this is to open the existing
Standard form which has already Browser ActiveX in it.

Here is the code

 static void ActiveX_Alternate(Args _args)


str         htmlContent;

TextBuffer  txtBuffer;

int         handle;

WinInet     wi = new WinInet();


= wi.internetOpenUrl(‘’);



htmlContent = wi.internetReadFile(handle);


txtBuffer = new TextBuffer();




 Drawback: The form caption stills remains the KMKnowledgeAnalogMeter “form caption

 Attached is the error and the output of the second job


6 Responses to “Problem when creating a dynamic form with ActiveX control & Solution :)”

  1. Jeff Says:

    after replacing activex.className(\’{8856F961-340A-11D0-A96B-00C04FD705A2}\’);  with activex.className(\’{25336920-03F9-11cf-8FD0-00AA00686F13}\’), the job ActiveX_DynamicForm works.Here is my job:
        Form                    form;    FormRun                 formRun;    FormBuildDesign         formBuildDesign;    FormBuildActiveXControl formBuildActiveXControl;
        FormActiveXControl      formActiveXControl;
        COMDispFunction         webPreviewWrite;    COMVariant              text;    COM                     ctrl;
        Args                    args;    WinInet                 winInet;
        int                     handle;    str                     htmlContent;    ;
        //open the web page and fetch web content — begin;    winInet = new WinInet();    handle  = winInet.internetOpenUrl("");    if (handle)    {        htmlContent = winInet.internetReadFile(handle);    }    winInet.internetCloseHandle(handle);    //open the web page and fetch web content — end;
        //create a dynamics form with activeX control to display web content — begin;    form                    = new Form("ActiveX Form", true);    formBuildDesign         =;    formBuildDesign.caption("view web content");    formBuildDesign.widthMode(FormWidth::ColumnWidth);    formBuildDesign.heightMode(FormHeight::ColumnHeight);    formBuildActiveXControl = formBuildDesign.addControl(FormControlType::ActiveX, "htmlControl");    formBuildActiveXControl.className(\’{25336920-03F9-11cf-8FD0-00AA00686F13}\’);    formBuildActiveXControl.widthMode(FormWidth::ColumnWidth);    formBuildActiveXControl.heightMode(FormHeight::ColumnHeight);    //create a dynamics form with activeX control to display web content — end;
        args                    = new Args();;    args.object(form);    formRun                 = classFactory.formRunClass(args);
        //set web content to activeX control–begin;    formActiveXControl      =\’htmlControl\’);    ctrl                    = new COM();    ctrl.attach(formActiveXControl.interface());    webPreviewWrite         = new COMDispFunction(ctrl, \’write\’, COMDispContext::Method);    text                    = new COMVariant();    text.bStr(htmlContent);"");;    //set web content to activeX control–end;;    formRun.detach();

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: