About Valentina XCMD...

Robert Brenstein rjb at rz.uni-potsdam.de
Sun May 16 21:07:42 EDT 2004


>Andre,
>
>>  humm... how do I address the VCXMD directly? I put it into externals
>>  property and reloaded the IDE, is this enought?
>
>Here's the basics that I use - the rest you can get from the docs Jan
>pointed you to:
>
>global gValentinaInit,gMainDBRef
>
>on StartupDB
>   get Valentina("SetDebugLevel",3)
>   if not(gValentinaInit) then
>     get
>Valentina("Init",20*1024*1024,YourMacLicenseCode,YourWindowsLicenseCode)
>     if (it contains "ERROR") then
>       put false into gValentinaInit
>       -- Call your error handler here
>     else
>       put true into gValentinaInit
>     end if
>   end if
>end StartupDB
>
>on ShutdownDB
>   if gValentinaInit then get Valentina("Shutdown")
>   put false into gValentinaInit
>end ShutdownDB
>
>on OpenDB pDBPath
>   put Valentina("Database_Open",pDBPath) into temp
>   if (temp contains "ERROR") then
>     -- call your error handler here
>   else
>     put temp into gMainDBRef
>   end if
>end OpenDB
>
>on CloseDB
>   get Valentina("Database_Close",gMainDBRef)
>   put "" into gMainDBRef
>end CloseDB
>
>-- Then to make a simple query that gets all the data from the People table
>put Valentina("Database_SQLSelectRecords",gMainDBRef,"SELECT * FROM People")
>into tRecs
>
>
>Hope this helps,
>
>Ken Ray
>Sons of Thunder Software
>Email: kray at sonsothunder.com
>Web Site: http://www.sonsothunder.com/


One word of warning, though. The above example will work nicely when 
only a single stack opens and closes Valentina. I mean closing the 
engine not db files. However, when working in IDE it is possible to 
have multiple stacks opening and closing Valentina, and one could 
close Valentina without another one knowing about it, leading to a 
likely crash. So, one should also have a global monitoring the number 
of open stacks. More complicated but more reliable approach is for 
gValentinaInit (in the above example) to be a counter of init 
requests (instead of being a simple true/false flag). Each open must 
be then matched but a close which descreases the count and actually 
closes the kernel only when it is 0.

>on StartupDB
>   get Valentina("SetDebugLevel",3)
    if (gValentinaInit=0) then
>     get
>Valentina("Init",20*1024*1024,YourMacLicenseCode,YourWindowsLicenseCode)
>     if (it contains "ERROR") then
>       put false into gValentinaInit
>       -- Call your error handler here
>     else
        put 1 into gValentinaInit
>     end if
     else
       add 1 to gValentinaInit
>   end if
>end StartupDB
>
>on ShutdownDB
    substract 1 from gValentinaInit
    if gValentinaInit = 0 then get Valentina("Shutdown")
>end ShutdownDB

If all your stacks use such a code, then you can close and open then 
in any order.

Robert Brenstein


More information about the use-livecode mailing list