realbasic-nug
[Top] [All Lists]

Re: Editfield and text encoding question

To: REALbasic NUG <realbasic-nug at lists dot realsoftware dot com>
Subject: Re: Editfield and text encoding question
From: "Joseph J. Strout" <joe at realsoftware dot com>
Date: Wed, 31 Aug 2005 08:30:34 -0600
Delivered-to: realbasic-nug at lists dot realsoftware dot com
References: <43158099 dot 7090806 at asialogique dot com>
At 6:04 PM +0800 8/31/05, Laurent Vidonne wrote:

The ciphertext, coming from a Memoryblock (ciphertext = m.Stringvalue ...), has no encoding. When I write cipherField.Text = ciphertext

...you're making a mistake. :) If you have a string with no encoding, then it is NOT valid text. But EditFields are only for editing text, not arbitrary binary data. So by doing this, you're telling REALbasic: "Here's some arbitrary binary data that I want you to nonetheless treat as text somehow. Do your best and I'll keep my fingers crossed."

it seems that RB applies the default UTF-8 encoding, which is fine with me.

I'm not sure that's what it does; I think it guesses the default 8-bit encoding for your system. But the exact behavior is undefined and you certainly shouldn't be relying on it.

What I don't understand is that it seems that the data is somehow changed : if I now try to decrypt cipherField.Text, I get a checksum error and garbage.

But of course. It's been converted to text, as well as it can. The mistake is in asking REALbasic to do so. You should either (a) not assign this arbitrary binary data to an EditField, or certainly not expect it to come back the same way, or (b) define a valid encoding for it (using DefineEncoding).

Best,
- Joe

--
Joe Strout                          REAL Software, Inc.

Vote for REALbasic (twice!) in the LinuxWorld Reader's Choice Awards:
http://linux.sys-con.com/general/readerschoice.htm
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>