![]() |
|
|||||||
| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
| Questions & Help Needed Post any question regarding Basic4ppc. |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi everyone,
I've got an error when I close a form and checks a method from an object. As it hasn't been created yet, I got an error (as expected). Not always the object is needed, so sometimes it doesnīt exists. Is there a way to check if an object exists prior to use it? (similar to FileExist function). Thanks in advance, Jesus. |
|
|||
|
Hi Erel and Agraham,
to Agraham: Yes, it was my first approach, but as the object not always exists, is not always needed to 'New' it. to Erel: Tried your code, but I canīt parse the objet to Objetexist function. I'll try to explain myself better. It's a Serial objet, and I got the 'undeclared array' error using Erel's code. The error I got is in the following sentence: Sub Form_Close If Serial1.PortOpen=true Then Serial1.PortOpen = false End Sub If Serial1 hasn't been created with the New method, I can't use it (obviously). What I was looking for is something like this: Sub Form_Close If ObjetExist(Serial1.) Then If Serial1.PortOpen=true Then Serial1.PortOpen = false End if End Sub or If Serial1.Exists then... but this method doesnīt exists, isnīt it? Thank you. |
|
||||
|
Erel's method does work but the result differs between the IDE and the optimised compiler for a pre-defined object. In the IDE the control exists even if it has not been Newed but when optimised it exists only after being Newed so this following code shows a "Yes" message box and Object appears in the list in the IDE, but optimised compiled there is no Yes message box and Object is absent from the control list.
Code:
Sub Globals
'Declare the global variables here.
Dim Ctls (0)
End Sub
Sub App_Start
'Object.New1
If ObjectExist("Object") Then
Msgbox("Yes")
End If
Ctls() = GetControls("")
For i = 0 To ArrayLen(Ctls())-1
msg = msg & Ctls(i) & crlf
Next
Msgbox(msg)
End Sub
Sub ObjectExist(obj)
ErrorLabel(ObjectExistErr)
Dim a
a = ControlType(obj)
Return true
ObjectExistErr:
Return false
End Sub
Last edited by agraham : 05-19-2008 at 06:23 PM. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Checking if registry key exists? | N1c0_ds | Questions & Help Needed | 3 | 10-21-2008 06:30 AM |
| SQL Table Exists? | tsteward | Questions & Help Needed | 3 | 05-02-2008 01:18 PM |
| Object Reference not set to an instance of an object | monster9999 | Questions & Help Needed | 9 | 01-15-2008 10:56 PM |
| object reference | dennishea | Questions & Help Needed | 6 | 08-15-2007 05:48 PM |
| Tab Object | anansath | Basic4ppc Wishlist | 1 | 06-08-2007 03:58 PM |