Is it possible to pass a parameter to a vfp com server using CreateObject("COMServer.Class", eParameter)
It seems to me that whatever I pass in eParameter it is always .F. within the INIT method and PCOUNT() always gives 0.
Regards
Darren Woodford
Woodford Computer Systems Ltd
http://www.woodfordcomputers.co.uk

passing parameters to vfp com servers using createobject
Jay1980_UK
Thanks for the additional information David. I am using a separate Startup() method so I guess that is along the same lines.
Thanks again.
cincyreds
Thanks Andy.
The problem I had was that the code in INIT needed to check the setting before the user had chance to set it. Ah well I have managed to rearrange my code now.
I was going off the VFP8 help file which has the following under CreateObject() function.
These optional parameters are used to pass values to the Init event procedure for the class. The Init event is executed when you issue CREATEOBJECT( ) and allows you to initialize the object.
Youngy
Hi Darren
>> Is it possible to pass a parameter to a vfp com server using CreateObject("COMServer.Class", eParameter)
I don't think so. I have always used:
oComObj = CreateObject("COMServer.Class" )
oComObj.RunAMethod( eParameter )
That certainly works. I am not sure that you can pass the parameters the way that you are trying to and the fact that you always end up with PCOUNT() = 0 would tend to suggest that you can't
LATER.... A quick trial suggests that you can't. The following code fails to set the property in the Init(), but works when called explicitly:
*** Create the object
o = CREATEOBJECT("comtest.xtest", 32 )
*** Did the parameter work
o.nInVal && No!
*** Call the method and pass the parameter
o.Runit(32)
*** Now all is well!
o.nInVal
DEFINE CLASS xTest AS Session OLEPUBLIC
INIT: Initialize
nInVal = 0
********************************************************************
***
********************************************************************
FUNCTION Init( tnInVal )
WITH This
.nInVal = tnInval
ENDWITH
ENDFUNC && Init
********************************************************************
RUNIT:
***
********************************************************************
FUNCTION Runit( tnInVal )
LOCAL llRetVal
WITH This
.nInVal = tnInval
ENDWITH
ENDFUNC && Runit
ENDDEFINE
Echo10
Thanks for the clarification Craig.
Be nice if the VFP help said that. :D
Yosi Taguri
Yes I did notice that. Conspicuous by their absence. No doubt it is an undocumented feature
Coretta
Christian44
Hi Darren
>> I was going off the VFP8 help file which has the following under CreateObject() function
Yes, but you will notice that the only examples are for VFP base/custom classes - no reference to COM objects at all. It looks as though the INIT() of a class compiled under the COM standard behaves differently - I confess I have no idea why, but that's certainly how it looks.
mandoman
Darren,
FWIW Init parameters limit the usefulness of the class. You can not drop the class onto a form or other class because you can't assign parameters at all. They don't work in a COM object as you've found. A lot of developers use a separate Initialize() method that can be called to do that work.