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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GUIDE ME OUT IF YOU CAN IMMDLY 2

Status
Not open for further replies.

narenkv

Programmer
Sep 20, 2002
43
IN
I am getting an error with Class definition Session not found . Can u guide me where i am wrong I have pasted the code below

IN MY MY_CLSFILE.PRG
--------------------

DEFINE CLASS My_COM AS SESSION
....
..
..
ENDDEFINE

IN THE FORM CLSFRM IN THE INIT EVENT
===================================

SET PROC TO MY_CLSFILE addit

MYCOMOBJ = CREATEOBJECT('MY_COM')


 
narenkv

What version of VFP are you using? The SESSION class was introduced with VFP7.0.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi

Mike Gagnon

Thanks For the solution , I installed service Visual Studio pack 5. The session class worked for me in VS6

Thanks
NAREN
 
Mike,

The SESSION class was introduced with VFP7.0.

Are you sure about that? I feel sure it was in the language earlier.

If I remember right, there were a couple of changes made in 7.0: some of the default settings were changed (EXCLUSIVE, for example); and all the built-in PEMs were automatically hidden, so that the class user only saw the PEMs defined by the programmer. But I am fairly sure the class itself was previously available.

Mike




Mike Lewis
Edinburgh, Scotland
 
MikeLewis

Are you sure about that? I feel sure it was in the language earlier.

You are most likely right, I tested the code in VFP6.0 and got an error, but hadn't realized that my version of VFP6.0 had no service pack installed.


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi
Mike Gagnon

Session Class is working fine . But I have a another problem.

define class baseclass as session
protected function calc()

return('base')

endfunction

enddefine

define class derived as baseclass

function calc()

return('derived')

endfunc

endefine

myobj=createobj('derived')
val=myobj.calc()

When I tried to execute it gives me error saying that method calc does not found.

So i removed the 'Protected' keyword from base class and typed in as

define class baseclass as session
function calc()

return('base')

endfunction

enddefine

Now It returns 'derived' as value. It works fine.
My problem is why the function does not overide when i use protected keyword for function calc.

So If I use protected keyword in base class in foxpro the overide functionality fails

Thanks
NAREN

 
narenkv

My undestanding of proctected functions is described in the help file:

Properties and methods that you designate as Protected can be accessed only by other methods in the class definition or in subclasses of the class.

So in order to access a protected function, you need to make a call to it from whitin the subclass itself.
P.S. You might want to avoid using baseclass as a class name, it might be a protected word. And check your syntax on ENDFUNC and ENDDEFINE.

Code:
myobj=Createobj('derived')
val1=myobj.Calc2()
Define Class baseclass1  As Session
	protected Function Calc
	Return('base')
Endfunc
Enddefine
Define Class derived As baseclass1
	Function Calc2
	  this.calc
Endfunc
Enddefine

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi

Mike Gagnon

Thanks for your sincere reply.

I saw that the same piece of code is working with java .i.e overriding the functions. Can U just let me know whether function overriding is posible in VFP like the code below

*base class
DEFINE CLASS baseclass as session
PROTECTED FUNCTION calc()

return('base')

ENDFUNCTION

ENDDEFINE

*derived class
DEFINE CLASS derived AS baseclass

FUNCTION calc()

return('derived')

ENDFUNC

ENDDEFINE

myobj=createobj('derived')
val=myobj.calc()

It generates error 'calc method/property does not exist.'

Thanks
NAREN
 

Please read the help file in VFP on protected functions, what you are trying to achieve is not possible in VFP, as the file states "methods that you designate as Protected can be accessed only by other methods in the class definition or in subclasses of the class."


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Just to correct some information. The Session class was first introduced with VFP 6.0, Service Pack 3...not VFP 7.0. It was improved in VFP 7.0.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
To elaborate,

Function overriding works fine, however if the function was defined in an ancestor class as Protected, then it will always be protected, even when you override it without the "PROTECTED" keyword. (I'm not sure if you can override it WITH the PROTECTED keyword...)

But, you can only access the protected method (original or overridden) from within another method of the same class.

So, to show your first example working:
Code:
* Class definitions must be after procedural code...
myobj=createobj('Example_BaseClass')
? myobj.Test()  && Should print "base", and does

myobj=createobj('Example_DerivedClass')
? myobj.Test()  && Should print "derived", and does
? myobj.Test2() && Should print "derived", and does
? myobj.Test3() && Should print "base", and does

DEFINE CLASS Example_BaseClass  AS Session
  PROTECTED FUNCTION calc()
    return('base')
  ENDFUNC
  FUNCTION Test()
    * Note: In the subclass, this function properly
    *  calls the overridden "calc" method.
    RETURN THIS.Calc()
  ENDFUNC
ENDDEFINE

DEFINE CLASS Example_DerivedClass AS Example_BaseClass
  FUNCTION calc()
    return('derived')
  ENDFUNC
  FUNCTION Test2()
    * Note this funciton does NOT override the function "Test"
    RETURN THIS.Calc()
  ENDFUNC
  FUNCTION Test3()
    * Note, this function deliberatly calls the parent class's method:
    RETURN Example_BaseClass::Calc()
  ENDFUNC
ENDDEFINE
 
Mgagnon wrote:
I tested the code in VFP6.0 and got an error, but hadn't realized that my version of VFP6.0 had no service pack installed.


Craigber wrote:
Session class was first introduced with VFP 6.0, Service Pack 3

That's interesting. The documentation for SP3 does indeed mention the Session class (as a 'fix'). But the class is described in the Help file for plain VFP 6.0. (without the SP). I guess Microsoft intended to put it into 6.0, but for some reason it didn't make it until SP3.

Mike




Mike Lewis
Edinburgh, Scotland
 
Mike,

That's exactly right. It was supposed to be there, but wasn't. They had some problems with COM servers and testing couldn't be completed before the ship date, so the feature was cut. It was added back in SP3.

Craig Berntson
MCSD, Visual FoxPro MVP, Author, CrysDev: A Developer's Guide to Integrating Crystal Reports"
 
Hi Mgagnon


I want to build a DLL (multi-threaded COM server) in Visual Foxpro Can you guide me how to create with some simple example.


Thanks

NAREN
 
narenkv

I want to build a DLL (multi-threaded COM server) in Visual Foxpro Can you guide me how to create with some simple example.

faq814-3381.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top