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!

datasessions and dlls

Status
Not open for further replies.

rickesilaw

Programmer
Jun 24, 2002
154
CA
I have a library that is loaded with start program that has a function that updates certain files. If i pass it the datasession the it runs ok. My question is, if it is created as a DLL, would I have to pass it the datasession? WHy - I have over 130 calls to this function and don't want to have to make 130 changes!
 
Im not sure if I understand. Are you using private or public datasessions?
 
I need private as many users and many screens open
 
Passing it a datasession won't really work unless you
create a ocx or fll(vfp specific dll) written in C/C++
using the fox API.

Even then, when called, the datasession of the dll will
be the same as the calling process.

Better to create your dll baseclass as a session object
and pass it the table names and values to update.

Matter of fact, you don't even have to use a session object
as the baseclass, the datasession of the dll will be
private automatically, since it initializes its own
environment.

But, you should base it on a session object with a
datasession of 2 if you'll have multiple instances of
the dll running on the same machine. If you don't, moving
the record pointer in one instance will affect the record
pointer in the other instances.

Let the dll handle opening the tables and performing the updates itself.

This all brings up another point. You'll have to set the
environment variables in the dll - such as excl off, cent on, etc.

I'm afraid you'll have to bite the bullet and re-think the design - unless I'm wrong:)

Darrell
 
After thinking about it some more, you can do what you
want by passing the dll a reference to the application
object (_vfp) and the datasession you want.

You'll still have to pass it values to perform the
update, but you can use the DoCmd() method of the
application object to access the data in the calling
processes' datasession.

Darrell

Below is a simple example.

You could pass the dll, application code as a text string
or the name of a application file to run and pass back
data to the calling process.


Code:
* Dll code built from project (myProject.pjx)
Define class clsDllCall as session olepublic

  DataSession = 2

  Function GetTableRecord()
    Lparam oAppObject, cTable, nDataSession
    Local oRec
    oAppObject.DoCmd("Set datasession to "+transform(nDataSession))
    oAppObject.DoCmd("Scatter name oRec")
    oAppObject.DoCmd("select "+cTable)
    oRec = oAppObject.Eval("oRec")
    Return oRec
  Endfunc

Enddefine

* Code that calls it
Use _samples+"\data\orders"

Local o, oRec

o = createobject("myProject.clsDllCall")

oRec = o.GetTableRecord(_vfp, alias(), this.datasessionid)
 
Thanks Darrell - I think you are right that we have to pass the datasessionid.value - This is what we were doing when passing to one of the prgs and it works so....

 
Once again, passing the datasessionid to a dll won't give
it access to the datasession of the calling process.

The dll will be operating in its own environment.

As stated, you'll need to pass the dll a reference to the
appliction object of the calling process so it can execute
method calls in the application objects environment.

This is totally different than calling a prg in the same
environment of a calling process.

As stated before, you can have the dll open the tables
needed itself and perform the required processing - which
is the simplest way.

Darrell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top