Forum > Win32/64
Lazarus 64 vs Lazarus 32 on Windows
Nicola Gorlandi:
Hi all,
I am trying to migrate from Lazarus 32 to Lazarus 64 (both 2.2.4) on Windows.
I have some compiler errors, most of them come from code as below (the error came from l := PCardinal(Cardinal(s) - 4)^; and the error is Illegal type conversion: "AnsiString" to "LongWord").
By the way, this code is from DIMime library porting from Delphi in Lazarus.
My question is, why on Win32 I do not have such error ?
Many thanks.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MimeEncodeString(const s: AnsiString): AnsiString;var l: Cardinal;begin if Pointer(s) <> nil then begin l := PCardinal(Cardinal(s) - 4)^; SetString(Result, nil, MimeEncodedSize(l)); MimeEncode(Pointer(s)^, l, Pointer(Result)^); end else Result := '';end;
PascalDragon:
--- Quote from: Nicola Gorlandi on October 25, 2022, 07:44:41 am ---My question is, why on Win32 I do not have such error ?
--- End quote ---
Cardinal has a size of 4 Byte while a Pointer (and thus also a AnsiString) is 8 Byte on 64-bit systems. Thus these are simply not compatible.
--- Quote from: Nicola Gorlandi on October 25, 2022, 07:44:41 am ---
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MimeEncodeString(const s: AnsiString): AnsiString;var l: Cardinal;begin if Pointer(s) <> nil then begin l := PCardinal(Cardinal(s) - 4)^; SetString(Result, nil, MimeEncodedSize(l)); MimeEncode(Pointer(s)^, l, Pointer(Result)^); end else Result := '';end;
--- End quote ---
Why don't you simply use Length(s)? You gain nothing by doing this yourself except potential for errors (also you should declare your size as SizeInt instead of Cardinal, because the type of the length of a string is platform dependant as well).
ASerge:
An example version, as the comments specified by @PascalDragon
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MimeEncodeString(const S: AnsiString): AnsiString;var InputSize, OutputSize: SizeInt;begin if S <> '' then begin InputSize := Length(S); OutputSize := MimeEncodedSize(InputSize); SetString(Result, nil, OutputSize); MimeEncode(Pointer(S)^, InputSize, Pointer(Result)^); end else Result := '';end;
Nicola Gorlandi:
Many thanks, this solve the issue.
Unfortunately I did not write the procedure, I downloaded somewhere years ago this library in order to code/uncode in base64.
I had already applied your suggestion to another procedure but I am not able to translate this part:
Pointer(Cardinal(Result) + InputSize)^
The function declaration is
function MimeDecodePartialEnd(out OutputBuffer; const ByteBuffer: Cardinal; const ByteBufferSpace: Cardinal): Cardinal;
I really appreciate your help.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---function MimeDecodeString(const s: AnsiString): AnsiString;var ByteBuffer, ByteBufferSpace: Cardinal; l: Cardinal; InputSize, OutputSize: SizeInt; begin if S <> '' then begin InputSize := Length(S); SetString(Result, nil, MimeDecodedSize(InputSize)); ByteBuffer := 0; ByteBufferSpace := 4; InputSize := MimeDecodePartial(Pointer(s)^, InputSize, Pointer(Result)^, ByteBuffer, ByteBufferSpace); Inc(InputSize, MimeDecodePartialEnd(Pointer(Cardinal(Result) + InputSize)^, ByteBuffer, ByteBufferSpace)); SetLength(Result, InputSize); end else Result := '';end;
Nicola Gorlandi:
Sorry I forgot a questiont: is it possible that Lazarus have a library to code / decode in base64 that I can use ?
many thanks again
Navigation
[0] Message Index
[#] Next page