Re: [twsocket] error Invalid code page (Peter Van Hove) (Arno Garrels)

2009-10-29 Thread Peter Van Hove

Thanks for the info.
But why do you need the ASCII and UTF-7 encoding at all?
Provided the text contained non-ASCII chars they would be replaced by
the default fail char ?, why not just save with default ANSI encoding,
the first 128 chars are always the same, in any codepage.
Also I've never seen a UTF-7 encoded text file so far, UTF-7 is
usually only used with 7-bit internet protocols such as email or
news.


It's a file save dialog and it looked fancy to allow the user to save as 
ASCII, UTF8, UTF7 etc.
I agree that the use is questionable but I leave it to the user to decide 
what format (s)he needs or likes.
Default I use UTF16 in fact. 


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] error Invalid code page (Peter Van Hove)

2009-10-26 Thread Peter Van Hove

So maybe somewhere in the code a wrong codepage is passed this this Win32
API call.



That won't raise an exception unless some wrapper function throwed one.


I sorted the problem out and it was not ICS (as what we agreed on already).

FYI

I use a save file dialog and allow the user to choose what encoding to use.
For that I use an example from the CodeGear help files.

{code:cpp}

Encodings-AddObject(ANSI, TEncoding::Default); // Default is ANSI
Encodings-AddObject(ASCII, TEncoding::ASCII);
Encodings-AddObject(UNICODE, TEncoding::Unicode);
Encodings-AddObject(UTF8, TEncoding::UTF8);
Encodings-AddObject(UTF7, TEncoding::UTF7);
SaveDialog-Encodings-Assign(Encodings);
// ...
int EncodingIndex = SaveDialog-EncodingIndex;
TEncoding* Encoding = 
dynamic_castTEncoding*(SaveDialog-Encodings-Objects[EncodingIndex]);

Edit-Lines-SaveToFile(FileName, Encoding) ;

{code}

I had NO idea that default ASCII (20127) may not be available on a user's 
system.
Two people who reported the problem did not have it checked by default in 
the regional settings.

As a result using TEncoding::ASCII VCL throws an exception.


I now do the following:

{code:cpp}

try {
Encodings-AddObject(ANSI, TEncoding::Default); // Default is ANSI
}
catch(...) {}
try {
Encodings-AddObject(ASCII, TEncoding::ASCII);
}
catch(...) {}
try {
Encodings-AddObject(UNICODE, TEncoding::Unicode);
}
catch(...) {}
try {
Encodings-AddObject(UTF8, TEncoding::UTF8);
}
catch(...) {}
try {
Encodings-AddObject(UTF7, TEncoding::UTF7);
}
catch(...) {}

{code}

And ASCII is nicely skipped when not available.
I had NO idea that ASCII in fact could be disabled in the regional settings
or that a default installation would not enable it.
For safety I obviously do the same to all the other code pages as well



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] error Invalid code page (Peter Van Hove)

2009-10-25 Thread Arno Garrels
- Original Message - 
From: Peter Van Hove pe...@smart-projects.net
To: twsocket@elists.org
Sent: Sunday, October 25, 2009 12:21 PM
Subject: [twsocket] error Invalid code page (Peter Van Hove)


 But I did a search in the files for Invalid code page and I
 couldn't find anything ... so I fear I'm barking up the wrong tree
 anyway.

 But then ... if anybody has an idea, let me know.

 I don't believe it's in ICS.
 Anyway the easiest way to catch this bug reliable was to include, for
 example, MadExcept into your project that the generates a bug report
 including a nice stack trace with source code line numbers.
 MadExcept comes with its own email clients so the user is able
 to send you the bugreport with a single mouse click.
 
 Thanks for the MadExcept tip Arno, I will check it out.
 
 Meanwhile I was searching the net for this errror and I came accross a post:
 https://forums.codegear.com/thread.jspa?threadID=9290
 
 Where it said:
 The error is actually coming from Windows, not Delphi,
 when TEncoding's constructor passes $ to the Win32 API GetCPInfo()
 function and it fails.

Passing an invalid codepage to GetCPInfo will let the function fail
with return ERROR_INVALID_PARAMETER, the exception is actually
raised in the constructor of the TMBCSEncoding class, ICS does not use 
TEncoding but uses the WinAPI directly for custom string convertions.
If there ever was an invalid codepage passed to the WinAPI you would 
get back some garbage string instead of an exception.

Any application that includes SysUtils will initialize two instances
of TMBCSEncoding on initialization, one with codepage CP_ACP and 
another one with codepage CP_UTF8, both should exist on any windows 
system (AFAIK).

 
 So maybe somewhere in the code a wrong codepage is passed this this Win32 
 API call.

That won't raise an exception unless some wrapper function throwed one.

 So I searched all files in my project for GetCPInfo and compiled this 
 list:

OverbyteIcsCharsetUtils isn't included in the THttpCli and also won't raise 
an exception Invalid Codepage. OverbyteIcsCharsetUtils is currently used by 
the SMTP, MimeDecoder and TIcsCharsetComboBox source only (if memory serves
well). The SMTP clients may raise an exception Invalid charset. 
TMimeDecode may raise 'Code page ' + _IntToStr(Value) + '' +
'is not a valid ANSI code page or currently not installed'.
In OverbyteIcsStreams TIcsStreamReader/Writer would throw an exception with
SysErrorMessage(ERROR_INVALID_PARAMETER) if GetCPInfo failed, however 
currently both classes are not yet used in ICS.   

--
Arno Garrels
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] error Invalid code page (Peter Van Hove)

2009-10-25 Thread Peter Van Hove

Where it said:
The error is actually coming from Windows, not Delphi,
when TEncoding's constructor passes $ to the Win32 API GetCPInfo()
function and it fails.


Passing an invalid codepage to GetCPInfo will let the function fail
with return ERROR_INVALID_PARAMETER, the exception is actually
raised in the constructor of the TMBCSEncoding class, ICS does not use 
TEncoding but uses the WinAPI directly for custom string convertions.
If there ever was an invalid codepage passed to the WinAPI you would 
get back some garbage string instead of an exception.


Got it !

I'll keep looking
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


[twsocket] error Invalid code page

2009-10-22 Thread Peter Van Hove

Hi guys,

I posted below quote in the embarcadero.public.cppbuilder.ide newsgroup.

My first reaction was that this is a Borland issue, but since I use two 
components (ICS and DragDrop) I need to make sure that it's not coming from 
something else.
This is on a user's system and I can't debug the situation to find out 
myself.


So my question, is it possible that ICS causes the error Invalid code page 
?

Is it an error in one of the routines ?

If no then I simply keep looking further ...

I use ICS (a slightly older rev I'm sure as I haven't updated the code in a 
while) on BCB 2009




This is a weird one.

My app, built with CB2009, starts with an error Invalid code page on a
user's system (XP system)

(This is a user reported problem, I do not get this error)

Is this a known problem and what to do about it ?

// ...

So I asked this person to run the same app built with BCB5 (I use the same
code base for both compilers (exceptions for main form etc.))
The BCB5 app runs fine.

I asked for his non-unicode codepage and he seems to use a tool for that
(SIW)
The feedback:

Codepage: 1255
Default OEM codepage: 862
Default EBCDIC code: 500

PS. an XP SP3 system (Hebrew settings)

So what part of the compiler creates this Invalid code page because it is
not coming from me.


/ 


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] error Invalid code page

2009-10-22 Thread Arno Garrels
Hello Peter,

Would be nice to know what ICS components you actually use.

--
Arno Garrels



Peter Van Hove wrote:
 Hi guys,
 
 I posted below quote in the embarcadero.public.cppbuilder.ide
 newsgroup. 
 
 My first reaction was that this is a Borland issue, but since I use
 two components (ICS and DragDrop) I need to make sure that it's not
 coming from something else.
 This is on a user's system and I can't debug the situation to find out
 myself.
 
 So my question, is it possible that ICS causes the error Invalid
 code page ?
 Is it an error in one of the routines ?
 
 If no then I simply keep looking further ...
 
 I use ICS (a slightly older rev I'm sure as I haven't updated the
 code in a while) on BCB 2009
 
 
 
 This is a weird one.
 
 My app, built with CB2009, starts with an error Invalid code page
 on a user's system (XP system)
 
 (This is a user reported problem, I do not get this error)
 
 Is this a known problem and what to do about it ?
 
 // ...
 
 So I asked this person to run the same app built with BCB5 (I use the
 same code base for both compilers (exceptions for main form etc.))
 The BCB5 app runs fine.
 
 I asked for his non-unicode codepage and he seems to use a tool for
 that (SIW)
 The feedback:
 
 Codepage: 1255
 Default OEM codepage: 862
 Default EBCDIC code: 500
 
 PS. an XP SP3 system (Hebrew settings)
 
 So what part of the compiler creates this Invalid code page because
 it is not coming from me.
 
 
 /
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be