PlanetSquires Forums

Support Forums => General Board => Topic started by: Richard Kelly on April 09, 2014, 11:33:32 PM

Title: Globals and POWERCOLLECTION
Post by: Richard Kelly on April 09, 2014, 11:33:32 PM
I had a thread on the PB forums at:


http://www.powerbasic.com/support/pbforums/showthread.php?t=54692
(http://www.powerbasic.com/support/pbforums/showthread.php?t=54692)

I had decided to simplify my use of globals and use a POWERCOLLECTION class and I wrote a quickie wrapper class for it.

There was a response regarding the use of THREADSAFE on the methods. I included that after all my hours of pouring through Jose's includes and seeing him use it. Until Jose says otherwise, I'm inclined to stick with his PB class designs.

Rick
Title: Re: Globals and POWERCOLLECTION
Post by: José Roca on April 10, 2014, 04:03:17 AM
That depends... I did add them to the clases that deal with databases (ODBC, SQLite) because there are some instance variables to protect.

In you class, there isn't any need of it, because you don't use instance variables that can change of value between thread calls.
Title: Re: Globals and POWERCOLLECTION
Post by: Richard Kelly on April 10, 2014, 07:40:22 AM
The only INSTANCE variable is a POWERCOLLECTION. Is it already a reentrant, thread-friendly object in it's own right? This app does spawn a few worker threads.

Rick
Title: Re: Globals and POWERCOLLECTION
Post by: José Roca on April 10, 2014, 09:50:13 PM
But it does not change of value and, therefeore, does not need to be protected.
Title: Re: Globals and POWERCOLLECTION
Post by: Richard Kelly on April 11, 2014, 12:09:58 AM
Quote from: Jose Roca on April 10, 2014, 09:50:13 PM
But it does not change of value and, therefeore, does not need to be protected.

Thank you for your sage evaluation. It is much more civil here than the PB forums and I don't know what got into me to put up anything there.

Rick
Title: Re: Globals and POWERCOLLECTION
Post by: Richard Kelly on April 14, 2014, 04:12:54 AM
I'm having a brain freeze here and thought you guys would be nicer than the PB folks.

I have an array of UDT's that I want to stash in a variant and later get them back and just can't figure it out.

The only syntax that seems to work is:


local vAny as Variant
local arAny(0) as MY_UDT

'
'....fill arAny with multiple UDT's
'
'

let vAny = arAny()
Erase arAny
Let arAny() = vAny


an that always result in arAny being empty.

It's got to be a simple thing to do and maybe variant types just can't hold arrays of UDT's.

I can "uncouple" the UDT and just store all the values in a STRING array and that works.

Rick
Title: Re: Globals and POWERCOLLECTION
Post by: David Kenny on April 14, 2014, 06:13:33 AM
Richard,

Excerpt from the PB Manual under the topic: LET statement (with Variants)
QuoteLET VrntVar = array()

An entire PowerBASIC array is assigned to a variant variable. In the case of a string array, PowerBASIC automatically handles Unicode conversions needed for the COM specification. Array assignment is limited to the following data types: BYTE, WORD, DWORD, INTEGER, LONG, QUAD, SINGLE, DOUBLE, CURRENCY, or STRING, as Windows does not support all PowerBASIC data forms.

It would appear that UDT Arrays are not supported directly.  You should be able to convert each UDT to a string and save it in a string array.  Converting it back when you need it.  I think it might be more trouble than it's worth.  Of course, that would be up to you.

David