|
|
|||||||
Hi all again, I just upgraded to KIX4.10a and I've encountered a problem. I use KIXGui to create a form (and later a progressbar): code:But when I run it I get:$root = CreateObject("KIXGUI.Desktop") Script error: IDispatch pointers not allowed in expressions! If Len($root) = 0 How do I check if the object is created? Where is this function change documented? |
||||||||
|
|
|||||||
yes. object-handles are not kixtart variables but pointers. you can't check for the length. rather I suggest you checking error and/or vartype. cheers, |
||||||||
|
|
|||||||
oh and best documentation is here. just read: http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=13;t=000194 cheers, |
||||||||
|
|
|||||||
Strange.... It worked with Kix4.02!!! This comes from an KIXGUI example: quote:So there must be a change somewhere |
||||||||
|
|
|||||||
Thnx Lonkero, this works: code:if not $root |
||||||||
|
|
|||||||
yes there is change. but the change is not wrong. as I said it's objecthandle-pointer. there is no way kix can do pointer to string translation (as pointer is not kix variabletype). it was perhaps handled before something like: if it can't be translated there is something. and that's why len returned something. for some reason (maybe some new feature or just disallowing wrong syntax) ruud has removed it. so, it's more than expected error. just it's not so well documented. haven't tried but what happens with 4.02 if you do: CreateObject("KIXGUI.Desktop") without placing the handle to variable? it's just the same thing. |
||||||||
|
|
|||||||
Even this syntax: if not $root isn't best pratice anymore (not so much with KixGUI, but with most other MS COM objects] as Ruud introduced DEFAULT PROPERTIES with 4.10 - which has changed the KOM landscape quite a bit. Suggest best practice is to do this: $root = CreateObject("KiXGUI.Desktop") if @ERROR ... or maybe this (not a big fan) ... $root = CreateObject("KiXGUI.Desktop") if vartype($root) = 9 ; Object Handle [shrug] |
||||||||
|
|
|||||||
shawn, just said the same in first post. well, he will return when that "if not" will stop working and then we can point back to this topic... |
||||||||
|
|
|||||||
yap - as usual, your way ahead of me. |
||||||||
|
|
|||||||
well, it probably is just that it's morning there and that makes you... well your fingers little slow. |
||||||||
|
|
|||||||
I chose the "if not $root" checking because 1) it works (at least for now) and 2) because I use KiXGUI with my logon script and I wrote it to handle both KiXGUI output and console output if the client is unable to register KiXGUI for some reason. Therefore, I have to make checks throughout my script to verify that KiXGUI is running. My original script was based on the example in the KiXGUI.zip file which I'm finding out now is rife with things not considered 'best practice.' I may change it in the future to something more like this... code:$root=createobject("KiXGUI.Desktop") |
||||||||
|
|
|||||||
alex could help with this. when he has last time updated the package? I have somekind of memory-block that the development has stopped or uttleast no new versions has been introduced here. so, probably the documentation is not 4.10 compliant... alex? [ 10 July 2002, 15:15: Message edited by: Lonkero ] |
||||||||
|
|
|||||||
Last kixgui release was little after kixtart 4.02, so yes, no compliance with 4.10a |
||||||||
|
|
|||||||
Guys, the if not $root is functioning fine. But you suggest I'd use if @error instead! Why? I don't understand the "not so much with KixGUI, but with most other MS COM objects" thingy. Can you make some things more clear for me? |
||||||||
|
|
|||||||
Because it's not really a variable but a pointer. By using @ERROR you make sure that there was no error in creating the object. This would be clean and proper programming syntax. code:$object=CreateObject('KIXGUI.Desktop') |
||||||||
|
|
|||||||
What if we wrap it in a UDF and bury the object check in there? Since KiXtart 4.10 supports default properties and methods, how does one distinguish between an object with default properties or methods and one without any default properites? The following code serves two purposes. First, it is an example of the UDF discussed above. Second, attempting to print the object yields text for the "Excel.Application" object, a zero (Boolean) for a failure to create the object, and a catastrophic script failure for the "WScript.Shell" object which apparently doesn't have default properties. I used two if statement just to verify the 'NOT' or lack thereof did not behave differently than expected. Execute with 4.10. code:Break on [ 13 July 2002, 08:01: Message edited by: Howard Bullock ] |