It's more ideal to have such a functionality in the same data session.
When you call a PRG it will run in the same data session as the caller, which makes me wonder what differs in your situation. An object lives in the data session it's created in, but not a function or a PRG.
Let me verify what I claim:
Code:
o = CreateObject("mysession")
o.currentsession()
? fn_currentsession(), Set("Datasession")
o = .null.
Define Class mysession as session
procedure currentsession()
? fn_currentsession(), Set("Datasession"), this.datasessionid
endproc
EndDefine
Function fn_currentsession()
return Set("Datasession")
Indeed the fncurrentsession() function called is either in the same datasession as the object "o" or as the code of the default session, the function is not living anywhere, it's no object. Therefore it returns the same datasession id as the callee itself does and any pair of fn_currentsession() and Set("Datasession") is the same number. So you shouldn't have a problem and could just pass in the alias name to work on to your my_update.prg or my_update() function.
That said, even normal objects (ie objects based on the custom class) are living in some datasession, as demonstrated here:
Code:
Store .null. to o,o2,o3
o = CreateObject("mysession") && o creates mycustom as o2 within its init()
o3 = CreateObject("mycustom")
? "mysession:"
o.currentsession()
? "mycustom created from mysession:"
o2.currentsession()
? "mycustom created from code in default session:"
o3.currentsession()
? "fn and Set('Datasession') called from default session:"
? fn_currentsession(), Set("Datasession")
Store .null. to o,o2,o3
Define Class mysession as session
Procedure init()
o2=CreateObject("mycustom")
procedure currentsession()
? fn_currentsession(), Set("Datasession")
endproc
EndDefine
Define Class mycustom as custom
procedure currentsession()
? fn_currentsession(), Set("Datasession")
endproc
EndDefine
Function fn_currentsession()
return Set("Datasession")
The o (mysession) object is starting its own new session, the o2 object created within it is also living in that session. The o3 object (also mycustom) created by the default session code is living in the default session.
The session number or datasessionid is not a property of every object, but still every object is in one. Otherwise controls wouldn't work, they are objects themselves and if they wouldn't be associated with the same datasession as the form and its dataenvironment they couldn't bind data of it, could they? So it's not a big surprise.
Therefore your my_update may either be a function or prg, when you do structural programming. My_update() could also be a method of a base class any related class inherits, so data maintenance or business logic objects live in the same datasession as the table(s) they maintain. In either case you don't have such problems. You only get such a problem if you put the my_update code inside one object that obviously can't live in all datasessions at the same time. You're breaking the encapsulation principle, if that's the case, but I don't think so.
I think you just never tried to access the same table or cursor within the function, which would be as easy as passing on the alias name as parameter tcAlias, and the SELECT (tcAlias) to select it and address fields of it, scan it or even query it with SQL.
Bye, Olaf.