Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Shared variables
Message
De
28/07/2002 10:37:44
 
 
À
26/07/2002 01:21:31
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00682871
Message ID:
00683334
Vues:
29
This message has been marked as a message which has helped to the initial question of the thread.
>When I create COM Server in Foxpro which is supposed to be used from two applications is there any possibility to have sort of static ( in terms of being created once for all instances ) variables with the possibility to reassign value.
< snip >
>Or maybe other mechanism is possible.
< snip >

Use external files. Each COM class instance runs in separate memory area for its own thread and you cannot easily pass variables between the threads.

You can use
SAVE TO myvar.dat
Restore from myvar.dat
But according to me better will be to have the same table opened as shared between instances and to have the following code for saving data
* update code
SET REPROCESS TO 2 SECONDS

IF !Used([MyVars]) Then
SELECT 0
USE MyVars SHARED
Else
SELECT MyVars
EndIF

IF FLOCK(ALIAS()) Then
Locate for VarName=[VariableToUpdate]
Replace VarValue with VarToMemo(m.VariableToUpdate)
UNLOCK IN (ALIAS())
ENDIF
VarToMemo() is supposed to convert variable to textual expression so that it can be stored in a memo. For example it can be conversion to Evaluate expression (when you call evaluate function over such expression you recieve the original value).
E.g.
DATETIME values are converted to
[DATETIME(]+;
transform(Year(myDateTime))+[,]+;
transform(Month(myDateTime))+[,]+;
transform(Day(myDateTime))+[,]+;
transform(Hour(myDateTime))+[,]+;
transform(Minute(myDateTime))+[,]+;
transform(Sec(myDateTime))+[)]
String values are converted like this
["]+Strtran(MyString,["],["+chr(34)+"])+["]
(Note that you may have problems with string values longer than 255 characters.)

And so on...
As for object variables - you may use ObjectToXML and XMLToObject from Rick Strahl's WebConnection. If you need sharing object variables - better do all the things using XML.

When you need to read the data you may have code like the following:
IF !Used([MyVars]) Then
SELECT 0
USE MyVars SHARED
Else
SELECT MyVars
EndIF

Replace VarName with VarName &&This to force VFP to purge its cursor memory cache
Locate for VarName=[VariableToRead]
m.VariableToRead = MemoToVar(VarValue)
MemoToVar() is supposed to be the reverse function of VarToMemo()

As you see - it is up to your decision how to acomplish it - here I have provided only scratch for the needed code.

Note that with this approach you cannot share SQLConnect handles - they are VFP application specific and each COM class instance has corresponding VFP application class instance.

HTH
Zlatin Zlatev,
MCSD (VS6)

Make solutions, not programs!

Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform