Archive: Issues on NSIS.pas


Issues on NSIS.pas
Dear all,

my plugins should in the (near) future support unicode. The plugins are developed in Delphi 6 without any unicode support. Now I got Delphi XE2 and I refresh the current NSIS.pas from the 2.46 release to my project.

But with this update I got some strange issues:

1. My plugin crashes in the Init-Method in this line:

extrap := g_extraparameters^;

I think "g_extraparameters" is nil and this is the reason why it crashes. Without this line it works.

2. The method "LogMessage" typecasts to "PAnsiChar" in this line:

item.pszText := PAnsiChar(Msg);

This will not work in Delphi Vesions which supports Unicode by default. It must be:

item.pszText := PChar(Msg);

or

item.pszText := PWideChar(Msg);

3. After fixing the first to points in the NSIS.pas everything looks ok and my plugin works with the NSIS Unicode version without any problems. If I use the same Plugin DLL in the "ANSI"-Version of NSIS but this crashes during the execution of my NSIS-Setup.

The reason why it crashes is the following line in the method "PopString":

Result := PChar(@th.text);

If I change it to...

Result := String(PAnsiChar(@th.text));

...and it works. At this point I'm helpless because I don't understand why this works (or better why the first line doesn't work). Maybe some user of this board or another NSIS developer can give me a hint about this problem?

Maybe this can be solved in a way that NSIS.pas can be used for "ANSI"-NSIS and "Unicode"-NSIS.

As a temporarily solution I used a condition compilation.

If I want to compile for "ANSI"-NSIS I use:

Result := String(PAnsiChar(@th.text));

If I want to compile fir "Unicode"-NSIS I use:

Result := PChar(@th.text);

Kind regards

Rainer


I have not used Pascal in years so I don't really remember the details.

Why do you need String(PAnsiChar( and not just PAnsiChar(@?

Is there something in the precompiler we can use to detect if compiling as unicode?


Hi,

I use the String typecast to avoid a compiler warning but it is not necessary. But the typecast to "PAnsiString" is the important point. It is necessary to typecast to "PAnsiChar" if the plugin should be executed in the "ANSI" version of NSIS otherwise you will not get correct string values. So this is my code at the moment:

-------
{$IFDEF NSIS_UNICODE}
Result := PChar(@th.text); // PChar is here PWideChar
{$ELSE}
Result := String(PAnsiChar(@th.text)); // String TypeCast is only to avoid compiler warning
{$ENDIF}
-------

I thought that "AnsiStrings" are 100% complain to UnicodeString. Therefore I expect that the values in "th.text" should be converted to a UnicodeString in the "ANSI"-NSIS version but this will not work. Does anybody know why?

Kind regards

Rainer


In ANSI NSIS, Result should be a AnsiString.

Can you redefine types?

{$IFDEF UNICODE}
type string = UnicodeString
{$ELSE}
type string = AnsiString //or {$H}{$P+} ?OpenString? or RawByteString?
{$ENDIF}

PChar would also need fixing, maybe as a helper function? UnicodeString does not exist in older versions, there you would need to use WideString. (Not sure which version from http://docwiki.embarcadero.com/RADSt...piler_Versions)

See also:
http://www.embarcadero.com/images/dm...-migration.pdf


Hey,

the compiler directives {$H}{$P+} will not work. I just tried it.

The string type cannot be redefined but I can create an own String Type like

{$IFDEF UNICODE}
TString = UnicodeString;
PChar = PWideChar;
{$ELSE}
TString = AnsiString;
PChar = PAnsiChar;
{$ENDIF}

This will work but my current solution will work too. The problem is that I want to know why the typecast of "PChar(@th.text)" will not work in the ANSI version of NSIS.

Kind regards

Rainer


PChar is PWideChar is Delphi 2009 and PAnsiChar in older versions