I am successfully implement the "Assign", and "Concatenate" CompilerProc:
procedure fpc_ansistr_assign(var DestS: Pointer; S2: Pointer); [public, alias: 'FPC_ANSISTR_ASSIGN']; compilerproc;
var
SLen: SIZE_T;
begin
SLen := strlen( LPCSTR( S2 ) );
DestS := VirtualAlloc( nil, SLen, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE );
if (not (DestS = nil)) then
begin
FillChar( DestS^, SLen, #0 );
move( S2^, DestS^, SLen );
end else
begin
MessageBox( 0, 'Error: fpc_AnsiStr_Assign memory allocation fail.', 'Error', 0 );
ExitProcess( 1 );
end;
// TODO: add delete
//VirtualFree( DestS, 0, MEM_RELEASE );
end;
procedure fpc_ansistr_concat(var dst: String; const S1,S2 : String; cp: DWORD); compilerproc;
Var
S1Len, S2Len, S3Len: SIZE_T;
DestS: Pointer;
begin
S1Len := strlen( LPCSTR( S1 ) );
S2Len := strlen( LPCSTR( S2 ) );
S3Len := S1Len + S2Len + 1;
DestS := VirtualAlloc( nil, S3Len, MEM_COMMIT or MEM_RESERVE, PAGE_READWRITE );
if (not (DestS = nil)) then
begin
FillChar( DestS^, S3Len, #0 );
move( PChar( S1 )^, DestS^ , S1Len );
move( PChar( S2 )^, (PChar(DestS) + S1Len)^, S2Len );
dst := String( DestS );
end else
begin
MessageBox( 0, 'Error: fpc_AnsiStr_Concat memory allocation fail.', 'Error', 0 );
ExitProcess( 1 );
end;
end;
This is not simply portable, because I use win32api Windows 10 API Funktion's.
But for me it is okay - I have tiny .ExE - Goal reached so far.
Okay. This could be a nogo for productive System's - I am not a professional Programmer/Developer.
But for me it is enough.
Thanks for your patient, and Hints.