login about faq

I've been trying out your newly posted DataFlex examples and have gotten some of them working. Most have minor syntax problems which I’ll be happy to share but one I haven’t been able to figure out is the following. In the XML SearchForTag example (Same problem in a couple of others) the line “Get ComSearchForTag of hoXSearchRoot hoXBeginAfter "fruit" to vXFound” is sending a handle, hoXBeginAfter, to ComSearchForTag which throws an error since it’s expecting a variant.

    Handle hoXml
    Variant vXSearchRoot
    Handle hoXSearchRoot
    Variant vXBeginAfter
    Handle hoXBeginAfter
    Variant vXFound
    Handle hoXFound
    Boolean iSuccess
    Variant vXSearch
    Handle hoXSearch
    String sTemp1
    ...

    //  Search for all nodes having the tag "fruit";
    Get ComGetSelf of hoXml to vXBeginAfter
    If (IsComObject(vXBeginAfter)) Begin
        Get Create (RefClass(cComChilkatXml)) to hoXBeginAfter
        Set pvComObject of hoXBeginAfter to vXBeginAfter
    End
    Get ComSearchForTag of hoXSearchRoot hoXBeginAfter "fruit" to vXFound

Any idea what the correct code should be? I tried vXBeginAfter but no joy. I’m not all that great with Com stuff so am struggling with this a bit.

asked Apr 06 '15 at 08:15

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

edited Apr 06 '15 at 08:34


Thanks! Chilkat confesses that it is not an expert in the DataFlex programming language. The DataFlex examples, just as for the examples for all the programming languages on example-code.com, are generated from a single source. For minor syntax errors, please let me know and I'll fix the DataFlex back-end, regenerate, and re-publish.

In the case above, the 1st parameter of the SearchForTag method ("ComSearchForTag") should be a reference to the node in the XML tree where the search should begin. The search will begin at the sub-tree rooted at the caller node, and will traverse breadth-first looking for a match. It will return the 1st match after the "hoXBeginAfter" node is passed. The hoXBeginAfter cannot be NULL/Nothing in the ActiveX implementation (because of technical issues w/ the COM wrappings), and therefore the intent is to pass a node that is also a reference to the caller node (thus the call to GetSelf).

My current understanding of DataFlex/COM (which perhaps is incorrect) is that a method returning a COM object will return a Variant. Thus:

Get ComGetSelf of hoXml to vXBeginAfter
My current understanding (again, which might be incorrect) is that to pass COM object to a method as a parameter, the Handle should be passed. Thus we get the handle (safely) and then pass it:
        If (IsComObject(vXBeginAfter)) Begin
            Get Create (RefClass(cComChilkatXml)) to hoXBeginAfter
            Set pvComObject of hoXBeginAfter to vXBeginAfter
        End
        Get ComSearchForTag of hoXSearchRoot hoXBeginAfter "fruit" to vXFound
If this is incorrect, the code generation can be updated to fix it.

Part of the intent of using a separate COM object for hoXBeginAfter is to show that it can be any node in the XML tree (within the sub-tree rooted at the caller, otherwise the search will always return NULL/Nothing). If the hoXBeginAfter is simply going to be the caller node, the example can be simplified to this (by omitting the call to GetSelf..)

    // Notice we're passing hoXSearchRoot instead of hoXBeginAfter...
    Get ComSearchForTag of hoXSearchRoot hoXSearchRoot "fruit" to vXFound

link

answered Apr 06 '15 at 08:33

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

I don't think I explained myself as well as I could have. When DataFlex analyzes the Chilkat DLL it creates a class file with all the methods it finds in the DLL. For ComSearchForTag we get this definition:

Function ComSearchForTag Variant llafterPtr String llTag Returns Variant

In the example we have

Get ComSearchForTag of hoXSearchRoot hoXBeginAfter "fruit" to vXFound

In the example, hoXBeginAfter is a handle or integer, in the class the target parameter is a variant. This causes an illegal data conversion or essentially a casting error.

link

answered Apr 07 '15 at 11:02

NEForever's gravatar image

NEForever
1

Thanks! I'll look more closely and will fix the code generation and re-upload.

link

answered Apr 07 '15 at 11:12

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

I updated the DataFlex examples with your suggestions. Hopefully they're closer to being 100% syntactically correct.

link

answered Apr 08 '15 at 16:45

chilkat's gravatar image

chilkat ♦♦
11.8k316358421

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×1
×1

Asked: Apr 06 '15 at 08:15

Seen: 953 times

Last updated: Apr 08 '15 at 16:45

Related questions

powered by OSQA