October 30, 2025, 01:02:10 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


COM Dispatch Library Questions

Started by Locodarwin, April 07, 2008, 03:34:35 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Locodarwin

I'm using the new COM Dispatch library included with EBasic as of 1.6.  In fact I'm enjoying it very much and I should have a ton of examples to post sometimes soon, to show other folks some of the power it gives EBasic.

However, in my testing I've come across a few concerns/questions/problems:

1. If a COM object errors out because we plug bad values into it, there is no feedback other than the calling function (i.e. SetComProperty) returning a non-zero value.  Is there a plan to support COM error messaging at some point in the future?
2. Is there a plan to support COM events sometime in the future?  Via the dispatch library, that is.
3. Wouldn't it be advantageous for the sake of language simplicity & design to update the COM dispatch library in such a way that most (almost all) data types passed between EBasic and the called objects are variants?
4. What about dispatch method/property calls where the object identifier is implied or used more than once, as in this Excel VBA example:

.ActiveSheet.Range(.Cells(1,1), .Cells(5, 5)).NumberFormat = "0.00%"

I would expect to solve this problem by writing the following EB code:


SetComProperty(ExcelObject, ".ActiveSheet.Range(%o.ActiveSheet.Cells(%d, %d), %o.ActiveSheet.Cells(%d, %d)).NumberFormat = %s", oExcelObject, 1, 1, oExcelObject, 5, 5, "0.00%")


...but that doesn't seem to work.  Nor does this work:


SetComProperty(ExcelObject, ".ActiveSheet.Range(.Cells(%d, %d), .Cells(%d, %d)).NumberFormat = %s", 1, 1, 5, 5, "0.00%")


I presume the problem has to do with the fact that SetComProperty is being asked to express more than it can handle.

What's the solution to this?  An implementation of the "With" keyword?

My suggestion would be to make COM dispatching more integrated into the language, allowing the . (dot) operator full COM dispatch scope so that it can be used in a fashion similar to other BASICs, and leave the mechanics of it under the hood.

But I'll tell you what.  Getting a COM dispatch library in there in the first place was a huge step forward for the language.

-S

Ionic Wind Support Team

1. yes there will be error checking soon.

2. The dispatch library is limited in that respect.  To handle events you need to implement your own interface and methods, I've used Emergence classes for this with virtual functions.

3.  What would be the point of the helper library then?  Internally the passed types are converted to the appropriate variant structures.  The convenience is being able to use Emergence variable types directly.

4. You would have to do that in more than one statement.

.ActiveSheet.Cells(%d, %d)

Would return either a dispatch, pointer or ?  Don't know without looking up the interface details.  Then pass that retuen to the .Range call.

Have you tried this?:


SetComProperty(ExcelObject, ".ActiveSheet.Range(.ActiveSheet.Cells(%d, %d), .ActiveSheet.Cells(%d, %d)).NumberFormat = %s", 1, 1,  5, 5, "0.00%")


Paul.
Ionic Wind Support Team

Locodarwin

Quote from: Paul Turley on April 07, 2008, 04:27:42 PM
1. yes there will be error checking soon.

2. The dispatch library is limited in that respect.  To handle events you need to implement your own interface and methods, I've used Emergence classes for this with virtual functions.

3.  What would be the point of the helper library then?  Internally the passed types are converted to the appropriate variant structures.  The convenience is being able to use Emergence variable types directly.

4. You would have to do that in more than one statement.

.ActiveSheet.Cells(%d, %d)

Would return either a dispatch, pointer or ?  Don't know without looking up the interface details.  Then pass that retuen to the .Range call.

Have you tried this?:


SetComProperty(ExcelObject, ".ActiveSheet.Range(.ActiveSheet.Cells(%d, %d), .ActiveSheet.Cells(%d, %d)).NumberFormat = %s", 1, 1,  5, 5, "0.00%")


Paul.


Thanks for your reply.

1. That's great news!

2. That's a bummer.

3. I guess that's the crux of the problem, for me.  COM variables are pretty straightforward, but EBasic's strongly-enforced types frustrate me at times.  It would be nice to have the option to use a variant that worked intrinsically with all of EBasic's functions.

4. Thanks for your help.  Yes, I did try your example along with a couple other single-call approaches.  No love, there.  While it's not convenient to make additional calls, it does work, so I guess I'll continue along those lines.  I'm just trying to stimulate your thought processes re: how to approach the problem for future COM dispatch work.  Your current solution, while great & lifesaving, is less than elegant.  ;)

.ActiveSheet.Cells(%d, %d)

...returns a dispatch.

-S

Ionic Wind Support Team

Keep in mind that I am just providing the built in wrappers for the existing Dispatch Helper library.  Allowing the variable number of parameters in the C library to be used directly from Emergence for example.

http://sourceforge.net/projects/disphelper/

I chose that library for a number of reasons. 

1. It had a BSD license
2. I could make a C static library out of it. Which was compatible with our linker
3. It used printf style formatting to specify parameter type, something I am very accustomed to and easy to teach.
4. I needed it for the current contract I have, to parse XML files using MSXML2.DOMDocument.3.0, which was a lot easier than parsing them by hand, and for expediency so I didn't have write the interface descriptions.
5. It came with complete source code.

The library does come with examples, using a WITH macro, which shouldn't be too hard to convert once I have a need for it.

For Emergence it is elegant since it is a heck of a lot easier than using the low level COM functionality of the language.

Paul.
Ionic Wind Support Team

Locodarwin

Quote from: Paul Turley on April 07, 2008, 08:07:11 PM
Keep in mind that I am just providing the built in wrappers for the existing Dispatch Helper library.  Allowing the variable number of parameters in the C library to be used directly from Emergence for example.

Ah, I was not aware that this was a set of third party wrappers.  Thanks.

Quote from: Paul Turley on April 07, 2008, 08:07:11 PM
For Emergence it is elegant since it is a heck of a lot easier than using the low level COM functionality of the language.

True indeed.

-S