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;

    ;

    handle
= wi.internetOpenUrl(‘http://www.yahoo.com’);

    if
(handle)

    {

       
htmlContent = wi.internetReadFile(handle);

    }

 

    wi.internetCloseHandle(handle);

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

   
formBrowse.design().width(500);

   
formBrowse.design().height(500);

   
formBrowse.design().addControl(FormControlType::ActiveX, ‘Browser’);

    args =
new Args(formBrowse.name());

    args.name(formBrowse.name());

   
args.object(formBrowse);

   
formRun = classFactory.formRunClass(args);

   
formRun.init();

   
activex = formRun.design().controlName(‘Browser’);

   
activex.className(‘{8856F961-340A-11D0-A96B-00C04FD705A2}’);

    activex.height(1,1);

   
activex.width(1,1);

   
formRun.run();

   
ctrl.attach(activex.interface());

   
webpreviewWrite = new COMDispFunction(ctrl, ‘write’,
COMDispContext::Method);

   
text.bStr(htmlContent);

   
activex.open("");

   
webpreviewWrite.call(text);

    formRun.detach();

}

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();

    ;

    handle
= wi.internetOpenUrl(‘http://www.yahoo.com/’);

    if
(handle)

    {

        
htmlContent = wi.internetReadFile(handle);

    }

   
txtBuffer = new TextBuffer();

   
txtBuffer.setText(htmlContent);

   
KMKnowledgeFunctionShow::show(txtBuffer);

}

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

 Attached is the error and the output of the second job

Advertisements

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("http://www.yahoo.com");    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         = form.design();    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.name(form.name());    args.object(form);    formRun                 = classFactory.formRunClass(args);
        formRun.init();
        //set web content to activeX control–begin;    formActiveXControl      = formRun.design().controlName(\’htmlControl\’);    ctrl                    = new COM();    ctrl.attach(formActiveXControl.interface());    webPreviewWrite         = new COMDispFunction(ctrl, \’write\’, COMDispContext::Method);    text                    = new COMVariant();    text.bStr(htmlContent);    formActiveXControl.open("");    webPreviewWrite.call(text);    //set web content to activeX control–end;
        formRun.run();    formRun.detach();


Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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: