Page 1 of 1 1
Topic Options
#86643 - 2002-07-10 11:51 AM error when checking if object was created
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
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:
$root = CreateObject("KIXGUI.Desktop")
;
If Len($root) = 0
$x = MessageBox("Error creating KIXGUI
Object." + $nl + $nl + "Please register
KIXGUI.dll.", "tslogin.kix", 16+4096)
Exit (1)
EndIf

But when I run it I get:

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?
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#86644 - 2002-07-10 11:54 AM Re: error when checking if object was created
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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,
_________________________
!

download KiXnet

Top
#86645 - 2002-07-10 11:55 AM Re: error when checking if object was created
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
oh and best documentation is here.

just read:
http://81.17.37.55/board/ultimatebb.php?ubb=get_topic;f=13;t=000194

cheers,
_________________________
!

download KiXnet

Top
#86646 - 2002-07-11 12:26 AM Re: error when checking if object was created
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
[Confused] Strange.... [Confused]

It worked with Kix4.02!!!

This comes from an KIXGUI example:
quote:

Break on
;
; Inputbox.k2k
;
; A demonstration script for KiXGUI
;
; Kixtart v4.01
; KiXGUI 1.0
;
; Done by Alex.H
;

$root = CreateObject("KiXGUI.Desktop")
If Len($root)=0 ; KiXGUI not registered or not present
? "KiXGUI not registered"
Exit 1
EndIf

So there must be a change somewhere [Wink]
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#86647 - 2002-07-11 12:41 AM Re: error when checking if object was created
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
Thnx Lonkero,

this works:
code:
if not $root
? "KiXGUI not registered."
endif

_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#86648 - 2002-07-11 12:44 AM Re: error when checking if object was created
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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.
_________________________
!

download KiXnet

Top
#86649 - 2002-07-10 02:05 PM Re: error when checking if object was created
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
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]

Top
#86650 - 2002-07-10 02:10 PM Re: error when checking if object was created
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
shawn, just said the same in first post.
well, he will return when that "if not" will stop working [Roll Eyes]
and then we can point back to this topic...
_________________________
!

download KiXnet

Top
#86651 - 2002-07-10 02:12 PM Re: error when checking if object was created
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
yap - as usual, your way ahead of me.
Top
#86652 - 2002-07-10 02:14 PM Re: error when checking if object was created
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well, it probably is just that it's morning there and that makes you... well your fingers little slow.
_________________________
!

download KiXnet

Top
#86653 - 2002-07-10 03:11 PM Re: error when checking if object was created
Chris S. Offline
MM club member
*****

Registered: 2002-03-18
Posts: 2368
Loc: Earth
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")
if @error
? "KiXGUI not registered."
else
$GUIOK=1
endif


Top
#86654 - 2002-07-10 03:14 PM Re: error when checking if object was created
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
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 ]
_________________________
!

download KiXnet

Top
#86655 - 2002-07-12 01:48 AM Re: error when checking if object was created
Alex.H Offline
Seasoned Scripter

Registered: 2001-04-10
Posts: 406
Loc: France
Last kixgui release was little after kixtart 4.02, so yes, no compliance with 4.10a
_________________________
? getobject(Kixtart.org.Signature)

Top
#86656 - 2002-07-12 11:23 PM Re: error when checking if object was created
MightyR1 Offline
MM club member
*****

Registered: 1999-09-09
Posts: 1264
Loc: The Netherlands
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?
_________________________
Greetz,
Patrick Rutten

- We'll either find a way or make one...
- Knowledge is power; knowing how to find it is more powerful...
- Problems don't exist; they are challenges...

Top
#86657 - 2002-07-13 12:06 AM Re: error when checking if object was created
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11164
Loc: Boston, MA, USA
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')
if @ERROR
? 'Unable to create object 'KIXGUI.Desktop'
else
; now you can do whatever you want to do with your object
endif
; and don't forget to clean up your object after use
$object = ''

_________________________
There are two types of vessels, submarines and targets.

Top
#86658 - 2002-07-13 07:56 AM Re: error when checking if object was created
Howard Bullock Offline
KiX Supporter
*****

Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
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
? "Object1"
$object1=udfCreateObject('Excel.Application')
if $object1
? "Object Exists"
? $Object1
endif
if not $object1
? "No Object"
? $Object1
endif

? ? "Object2"
$object2=udfCreateObject('Bogus')
if $object2
? "Object Exists"
? $Object2
endif
if not $object2
? "No Object"
? $Object2
endif

? ? "Object3"
$object3=udfCreateObject('WScript.Shell')
if $object3
? "Object Exists"
? $Object3
endif
if not $object3
? "No Object"
? $Object3
endif


Function udfCreateObject($A)
Dim $B
$B = CreateObject($A)
If VarTypeName($B) = "Object"
$udfCreateObject = $B
Else
? "Error creating object '"'$A'"'"
$udfCreateObject = NOT 1
Endif
Endfunction



[ 13 July 2002, 08:01: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.069 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org