Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is a class definition available

Status
Not open for further replies.

Toman

Technical User
Mar 30, 2004
190
CZ
Hi,

In a form I use my own class defined in main program. During debugging I often omit start the program first and the form being started says:

[tt]Class definition XXX is not found.[/tt]

Please,is there a way to find out whether class definition is available in a memory. I was playing with aclass() function with no success.

- OR -

is there a way how to include class definition somewhere in a form.

Thank you, Tom (VFP7).
 
During debugging I often omit start the program first

You're risking some obscure failures here. If you run the form without running the start program first then you aren't testing the form in the correct runtime environment. You might debug it and get it working on its own but then find that the form only works on its own and won't work as part of the application.

If the main application is so huge that it's impractical to run it just to debug a simple form then write yourself a cut-down version as a test harness to make sure that the form is being tested in the right environment.

Geoff Franklin
 
Hi Geoff,

Thanks for your post. I understand and respect fully your recommendations. But still I'd like to know: is there a way to find out whether class definition is available in a memory in a given moment.

Tom.
 
Sure. Try to create an instance of the class and trap for the error.

Also, you can explicitly tell VFP where to find the class definition when you declare or instantiate the class in your form. This should keep the problem from happening in the first place.

Local loMyObject as MyClass of (wherever your definition is)

boyd.gif

SweetPotato Software Website
My Blog
 
Try to create an instance of the class and trap for the error.
Yes, this is clear and works for me.
Local loMyObject as MyClass of (wherever your definition is)
clause AS and OF was not included in previous version of VFP (ver 5 in my case) so I missed it. I will try it.

Thanks to all. Tom
 
Also, you can explicitly tell VFP where to find the class definition when you declare or instantiate the class in your form. This should keep the problem from happening in the first place.

Local loMyObject as MyClass of (wherever your definition is)


I'm not certain, but I don't think that this alone will help at all. The "AS class OF location" clause for LOCAL is used by IntelliSense for code auto-completion, but I'm pretty sure it will be ignored completely when executing the CREATEOBJECT or NEWOBJECT line... ie, this is good (though poorly documented) VFP code:
Code:
LOCAL loMyForm1 AS myForm1 OF myForms.vcx
...
loMyForm1 = NEWOBJECT( 'YourProgressWindow', 'YourForms.VCX' )
...
loMyForm1 = CREATEOBJECT( 'timer' )
...
loMyForm1 = CREATEOBJECT( 'mySession' )
...
loMyForm1 = CREATEOBJECT( 'myForm1' )

When writing the code, intellisense will pop up stuff for "myForm1", but when executing, it will easily find "YourProgressWindow" class in "YourForms.vcx" (provided that the file "YourForms.vcx" exists, and that class really exists in YourForms.vcx), and it will certainly find "timer" (since it's a base class), and it may or may not find "mySession" since no info is provided to locate it.

I'm fairly certain that the final creation of "myForm1" will follow the same rules as "mySession", and will receive no help from the "AS" clause on the LOCAL statement.

(again, I'm not advocating obscure/ugly/revolting code like the above... just using it to illustrate how the LOCAL "AS" clause doesn't affect what class really is referenced by the variable...)

- Bill

Get the best answers to your questions -- See FAQ481-4875.
 
I find out that in this case I'm generating problems to myself by placing the class definition into the main program. I'm not so familiar with classis and it looked naturally to put it there and besides the class definition can't be placed in a form.

Now I've tried to use class designer, save class into some library and SET CLASSLIB .. to this library in myForm.Load method

All problems with class availability disappear.
Thanks to all willing to help me.
Tom.
 
Hi Toman,

you could also SET PROCEDURE TO your main prg file and afterwards use the included class definitions. At least that is explained in the help on SET CLASSLIB about the order VFP locates class definitions.

As Geoff suggested, you may create some minimum version of your main prg, which starts your form instead of the main menu or main form or whatever you start normally.

You may suggest to add parameters to main prg and that way start main in DEBUG mode passing in the form you want to debug. And for preventing this to have an effect on the compiled EXE you can make use of _vfp.startmode to decide if debug mode is possible or not.

Bye, Olaf.
 
Tom,

You could also do something like this...

Code:
LOCAL lcCurClassLib

lcCurClassLib=SET("CLASSLIB")
IF !UPPER("Your Class Name") $ lcCurClassLib
	SET CLASSLIB TO "Your Class Name" ADDITIVE
ENDIF

Then create your object...

Code:
loReportsMenu = CREATEOBJECT('ReportsMenu')
loReportsMenu.Show()

RELEASE lc_CurClassLib



Greg Grewe
West Chester, Ohio
 
Hi Oleaf,

you are right,
Code:
SET PROCEDURE TO (...my main prg file)
works perfectly (finds a class definition in main program and loads it into memory). I don't understand how I could miss it.

Hi Grag,

this is in its way an answer to my original question. Only "class existence question" is cleverly converted to "class lib existence question".

Thanks to all, Tom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top