[FXRuby] marshalling objects to the fox registry

The Fox registry lets you save strings between app invocations. I tried
persisting an array by marshalling it to a string and writing the string
to the registry, but when I ran the app again, it choked on the null
chars in the string. Does this mean Fox strings can’t have null chars?

Does the registry’s setAsciiMode method have anything to do with this? I
tried calling setAsciiMode(false), but it didn’t seem to help.

Thanks for any help.

Hi Joel,

I don’t know about Fox and its registry but you could try to avoid
null chars by using a base64 encoding for the marshalled strings,
something like

s = [ Marshal.dump( my_object ) ].pack( ‘m’ )

These strings don’t include null or other special characters. To get
the marshalled object back you would do

my_object = Marshal.load( s.unpack( ‘m’ )[ 0 ] )

HTH

Regards,
Pit

···

On 11 Sep 2002, at 15:08, Joel VanderWerf wrote:

The Fox registry lets you save strings between app invocations. I
tried persisting an array by marshalling it to a string and writing
the string to the registry, but when I ran the app again, it choked on
the null chars in the string. Does this mean Fox strings can’t have
null chars?

Does the registry’s setAsciiMode method have anything to do with this?
I tried calling setAsciiMode(false), but it didn’t seem to help.

Joel VanderWerf wrote:

The Fox registry lets you save strings between app invocations. I tried
persisting an array by marshalling it to a string and writing the string
to the registry, but when I ran the app again, it choked on the null
chars in the string. Does this mean Fox strings can’t have null chars?

Correct, FOX strings can’t have embedded nulls. See Pit Capitain’s
response to your post for what sounds to me like a good workaround :wink:

Does the registry’s setAsciiMode method have anything to do with this? I
tried calling setAsciiMode(false), but it didn’t seem to help.

No, this method lets you pick between storing the FOX registry data in
an ASCII file (similar to the .INI files from Windows 3.1 days) versus
storing it directly in the Windows Registry. By default (on Windows),
stuff saved to the FOX registry is plopped into the Windows Registry.

Pit Capitain wrote:

I don’t know about Fox and its registry but you could try to avoid
null chars by using a base64 encoding for the marshalled strings,
something like

s = [ Marshal.dump( my_object ) ].pack( ‘m’ )

These strings don’t include null or other special characters. To get
the marshalled object back you would do

my_object = Marshal.load( s.unpack( ‘m’ )[ 0 ] )

Thanks, Pit. What I did was to simply use ‘\1’ and ‘\2’ as entry and row
delimiters in my two dimensional array of printable strings. But your
idea is much more general.