Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there an 'IsClass()' function?
Message
From
09/11/2003 07:36:25
 
 
To
08/11/2003 17:10:42
General information
Forum:
Visual FoxPro
Category:
Classes - VCX
Miscellaneous
Thread ID:
00847972
Message ID:
00848056
Views:
18
Hi Stefan,
What I want to do is something like this:
.....myMethod()
  do case
    case isClass( 'myClass1' )
      this.oObject = createobject( 'myClass1' )
    case isClass( 'myClass2' )
      this.oObject = createobject( 'myClass2' )
    otherwise
      this.oObject = createobject( 'myClass3' )
  endcase
currently I have to do something like this:
.....Error( nError ,cMethod ,nLine )
  this.nError = nError
  if nError = 1733 and cMethod = 'myMethod'
    return
  else
    dodefault( nError ,cMethod ,nLine )
  endif
.....myMethod()
  this.oObject = createobject( 'myClass1' )
  if vartype( this.oObject ) # 'O' and this.nError = 1733
    this.nError = 0
    this.oObject = createobject( 'myClass2' )
    if vartype( this.oObject ) # 'O' and this.nError = 1733
      this.nError = 0
      this.oObject = createobject( 'myClass3' )
    endif
  endif
>Your question is somewhat ill-defined. What is it that you want to achieve? Unless we know that it is impossible to give a good answer.
>
>CREATEOBJECT("CFoo") can fail for any number of reasons, even if instances of the class CFoo do currently exist in memory. You may have failed to supply the correct parameters that the .INIT event of the class expects and thus caused the .INIT to return .F., or Fox may have failed to find the class definition because it is not in the current effective class search path, or Fox may have failed to find the definition for the base class of CFoo for the same reason, or whatever.
>
>One way of avoiding the question IsClass() altogether for PRG-based classes is to put each class in its own .PRG and to have the program body return a newly created instance of the class:
>
>[code]
>* CFoo.prg
>
>lparameters uArg1, uArg2
>return createobject([CFoo], @m.uArg1, @m.uArg2)
>
>define class CFoo as CBar of CBar.fxp
>
> function init (cMeow, nPurr)
> * ...
>
>enddefine[/code]
>
>In user code you just say 'oFoo = CFoo("meow", 666)', without having to fart around with SET PROCEDURE, SET CLASSLIB etc. pp. Works like a charm.
Bill Morris
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform