realbasic-nug
[Top] [All Lists]

Re: Encodings changed?

To: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Subject: Re: Encodings changed?
From: Joe Strout <joe@inspiringapps.com>
Date: Mon, 29 Jun 2009 16:12:51 -0600
Authentication-results: mx.google.com; spf=neutral (google.com: 74.124.194.228 is neither permitted nor denied by best guess record for domain of realbasic-nug-bounces@lists.realsoftware.com) smtp.mail=realbasic-nug-bounces@lists.realsoftware.com
Delivered-to: listarchive@realsoftware.com
In-reply-to: <C66EF7D5.578C4%markus_winter@online.de>
Organization: Inspiring Applications, Inc.
References: <C66EF7D5.578C4%markus_winter@online.de>
Reply-to: REALbasic NUG <realbasic-nug@lists.realsoftware.com>
Sender: realbasic-nug-bounces@lists.realsoftware.com
User-agent: Thunderbird 2.0.0.22 (Macintosh/20090605)
Markus Winter wrote:

if I have a text file created on a Mac, drop it into my project, and put it
into an editfield with

EditField1.text = MacFile

then it displays correctly in RB2007R3 ­ it seems MacRoman is used as the
default encoding.

Could be -- I wouldn't recommend depending on that, however. You should instead always do something like:

 EditField1.text = DefineEncoding( MacFile, Encodings.MacRoman )

(or whatever encoding it actually is).

Does anyone know the exact nature of the change and when it happened? I
presume that now UTF8 is used as the default encoding, and not the system
one?

Could be -- but I wouldn't recommend depending on that, either. It might change. :)

  Dim enc as TextEncoding
  s = Macfile
enc=s.Encoding Exception err as NilObjectException
    MsgBox err.message

Although enc is Nil no error is raised and no MsgBox is being displayed.

Why would it? A NilObjectException is raised when you do something with (i.e. dereference) a nil object. Although enc is nil, you haven't tried to do anything with it.

If I however test with

  if enc = Nil then
    MsgBox "No encoding defined"
  else
    MsgBox enc.internetName
  end if

then I get the message box. What is the difference here?

Here, you're actually testing whether it is nil.

But note that the whole code snippet you posted is pointless -- you've read a file, which assigns the encoding value passed to ReadAll (which defaults to UTF-8 if you don't specify otherwise) to the string. You then stuff this into enc. This tells you nothing except the default value of that parameter, which is in the LR. In particular, it does NOT tell you the actual encoding of the file. Nothing can do that (in general).

Best,
- Joe

--
Joe Strout
Inspiring Applications, Inc.
http://www.InspiringApps.com


_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>


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