Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Safely share a variable between com-objects
Message
 
À
17/09/2001 12:24:42
Information générale
Forum:
Visual FoxPro
Catégorie:
COM/DCOM et OLE Automation
Divers
Thread ID:
00557345
Message ID:
00557399
Vues:
15
Eyvind,

You must build it as a COM EXE not a DLL. Take a look at this:
** test multi-use com exe

define class demo as session olepublic
    procedure init
        if type("gcData") <> "C"
	    public gcData, gnCntr
            gcData = ""
            gnCntr = 0
        endif
		
	gnCntr = gnCntr + 1
    endproc
	
    procedure destroy
	gnCntr = gnCntr - 1
    endproc
	
    function GetCurrentCounter
	return(gnCntr)
    endfunc
	
    procedure Set(tcNewValue)
	gcData = m.tcNewValue
    endproc
	
    function Get
	return(m.gcData)
    endfunc
	
enddefine
The trick is to declare the shared vars as public in the init (but only if they do not already exist.)

Also if you have more than 1 client that can update the vars you need some sort of synchronization to keep 2 clients from updating the variable at once.

HTH

>At last weeks devcon, I attended Nick Neklioudov's excellent session on building visual interfaces to COM objects, and I've been experimenting a bit on my own at home with this. However, there is one thing that I cannot get to work: How can I safely share a reference between several com objects residing on a server to another com object residing on the same server? I tried just using a public variable, and although I can access it from all of the objects, when I try to make further use of it, I get an OLE error saying something not very helpful like "Something went seriously wrong" (not exact, translated from Norwegian).
>
>Thank you in advance for any help.
>
>Eyvind
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform