Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2016-05

SysUtils.GetEnvironmentVariable(String) still uses GetEnvironmentVariableA

7 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Denis Kozlov

Hi,

In FPC 3.0.0 and TRUNK for Windows:

SysUtils.GetEnvironmentVariable(String) uses GetEnvironmentVariableA SysUtils.GetEnvironmentVariable(UnicodeString) uses GetEnvironmentStringsW

GetEnvironmentVariableA produces a result crippled by ANSI/OEM. Can it be replaced with a simple typecast of UnicodeString based function:

function GetEnvironmentVariable(const EnvVar: String): String;
begin
  Result := String(GetEnvironmentVariable(UnicodeString(EnvVar)));
end;

Denis

Reply by email

Denis Kozlov
to Denis Kozlov

P.S. A minor typo, GetEnvironmentVariableA should read GetEnvironmentStringsA.

Denis Kozlov wrote 17 lines
Hi, In FPC 3.0.0 and TRUNK for Windows: > SysUtils.GetEnvironmentVariable(String) uses GetEnvironmentVariableA > SysUtils.GetEnvironmentVariable(UnicodeString) uses GetEnvironmentStringsW GetEnvironmentVariableA produces a result crippled by ANSI/OEM. Can it be replaced with a simple typecast of UnicodeString based function: function GetEnvironmentVariable(const EnvVar: String): String; begin Result := String(GetEnvironmentVariable(UnicodeString(EnvVar))); end; Denis

Reply by email

Michael Van Canneyt
to Denis Kozlov

The typecase will not help you, since the result is an ansistring. The result will still be crippled.

The only solution for this is a unicode RTL.

Michael.

Denis Kozlov wrote 24 lines
P.S. A minor typo, GetEnvironmentVariableA should read GetEnvironmentStringsA. On 23 May 2016 at 13:31, Denis Kozlov wrote: > Hi, > > In FPC 3.0.0 and TRUNK for Windows: >> SysUtils.GetEnvironmentVariable(String) uses GetEnvironmentVariableA >> SysUtils.GetEnvironmentVariable(UnicodeString) uses > GetEnvironmentStringsW > > GetEnvironmentVariableA produces a result crippled by ANSI/OEM. Can it be > replaced with a simple typecast of UnicodeString based function: > > function GetEnvironmentVariable(const EnvVar: String): String; > begin > Result := String(GetEnvironmentVariable(UnicodeString(EnvVar))); > end; > > Denis >

Reply by email

Jonas Maebe
to Michael Van Canneyt

Michael Van Canneyt wrote on Mon, 23 May 2016:

The typecase will not help you, since the result is an ansistring. The result will still be crippled.

It would help when DefaultSystemCodePage is changed to UTF-8, as Lazarus does.

The only solution for this is a unicode RTL.

That is incorrect, since as he wrote the unicodestring version of GetEnvironmentVariable() already exists in our RTL today. It's just that it's only used if you pass it a unicodestring argument, which won't be be the case in most Lazarus programs by default.

Jonas

Reply by email

Michael Van Canneyt
to Jonas Maebe
Jonas Maebe wrote 8 lines
Michael Van Canneyt wrote on Mon, 23 May 2016: > The typecase will not help you, since the result is an ansistring. > The result will still be crippled. It would help when DefaultSystemCodePage is changed to UTF-8, as Lazarus does.

Should that not be multibytecodepage or so ?

Show quoted text 7 lines
> The only solution for this is a unicode RTL. That is incorrect, since as he wrote the unicodestring version of GetEnvironmentVariable() already exists in our RTL today. It's just that it's only used if you pass it a unicodestring argument, which won't be be the case in most Lazarus programs by default.

Aha. I didn't know we already had an overloaded version. I stand corrected !

Michael.

Reply by email

Jonas Maebe
to Michael Van Canneyt

Michael Van Canneyt wrote on Mon, 23 May 2016:

Show quoted text 11 lines
On Mon, 23 May 2016, Jonas Maebe wrote: > Michael Van Canneyt wrote on Mon, 23 May 2016: > >> The typecase will not help you, since the result is an ansistring. >> The result will still be crippled. > > It would help when DefaultSystemCodePage is changed to UTF-8, as > Lazarus does. Should that not be multibytecodepage or so ?

The proper way to change DefaultSystemCodePage is by calling SetMultiByteConversionCodePage(), yes.

Jonas

Reply by email

Denis Kozlov
to Jonas Maebe: Michael Van Canneyt wrote on Mon, 23 May 2016: It would help when DefaultSystemCodePage…
Jonas Maebe wrote 18 lines
Michael Van Canneyt wrote on Mon, 23 May 2016: The typecase will not help you, since the result is an ansistring. > The result will still be crippled. > It would help when DefaultSystemCodePage is changed to UTF-8, as Lazarus does. The only solution for this is a unicode RTL. > That is incorrect, since as he wrote the unicodestring version of GetEnvironmentVariable() already exists in our RTL today. It's just that it's only used if you pass it a unicodestring argument, which won't be be the case in most Lazarus programs by default.

So, do we agree that it would be beneficial to change SysUtils.GetEnvironmentVariable(String) to call the UnicodeString overload internally?

function GetEnvironmentVariable(const EnvVar: String): String;
begin
  Result := String(GetEnvironmentVariable(UnicodeString(EnvVar)));
end;

This would propagate to GetEnvironmentVariableUTF8 in Lazarus, where a ConsoleToUTF8 conversion should then be removed.

SysUtils.GetEnvironmentString(Integer) and
SysUtils.GetEnvironmentVariableCount() also call crippled GetEnvironmentStringsA.

Denis

Reply by email