[FEATURE REQUEST] SysUtils.TMarshaller type
Original Reporter info from Mantis: silvioprog
-
Reporter name: silvioprog
Original Reporter info from Mantis: silvioprog
- Reporter name: silvioprog
Description:
Hi.
The TMarshaller record is a high-level aid for marshalling arguments to and from OS / native API or interfacing with external libraries APIs. For example, take a look at this "hello world" Android only below:
<code>
var
M: TMarshaller;
begin
LOGI(TMarshaller.AsAnsi('Hello World').ToPointer);
end.
</code>
or this POSIX only function below:
<code>
function TryGetFileSize(const AFileName: TFileName; out ASize: Int64): Boolean;
var
Vst: _stat;
VMrshl: TMarshaller;
begin
if ((stat(VMrshl.AsAnsi(AFileName, CP_UTF8).ToPointer, Vst) <> 0) or
(not S_ISREG(Vst.st_mode))) then
Exit(False);
ASize := Vst.st_size;
Result := True;
end;
</code>
(the Windows only version uses TMarshaller too and calls the GetFileAttributesEx() function)
TMarshaller is very useful for who wants to port Delphi bindings for C libraries/drivers to Free Pascal or making them compilable in both compilers, without declaring a lot of IFDEFs or handling types like PAnsi*/PWide directly for each intended operating system / API encoding. And TMarshaller record is easy use: it does not need .Create/.Destroy or any RefCount handling, because it a record is auto-destruction.
Its documentation can be found here:
http://docwiki.embarcadero.com/Libraries/Tokyo/en/System.SysUtils.TMarshaller
(some demos can be found at Github repositories, eg.: https://github.com/Dennis1000/libpomelo-delphi/blob/master/Examples/echo-common/echo.pas and https://github.com/Dennis1000/libpomelo-delphi/blob/master/Source/Pomelo.Client.pas)
Mantis conversion info:
- Mantis ID: 32835
- Version: 3.1.1