SetString |
Top Previous Next |
User interface > Translation options > Input options > Extended "System.pas" > SetString
SetString doesn't exist in the C++Builder VCL. If this function is used in the translated code, an implementation of one's own is required. According to the Delphi help the declaration is:
procedure SetString(var s: string; buffer: PChar; len: Integer);
Also according to the Delphi help this declaration should be found in the System.pas. But only the following exists there:
procedure _SetString(s: PShortString; buffer: PChar; len: Byte);
Delphi2Cpp uses such declarations - by removing the underscore - if nothing else is found. Indeed, just for the SetString function. Delphi2Cpp corrects this declaration internally. But with the definition in d2c_system.pas, you don't need to write your own C++ implementation.
In d2c_system.pas there are three declarations of SetString.
procedure SetString(var S: AnsiString; Buffer: PChar; Len: Integer); overload; procedure SetString(var S: WideString; Buffer: PWideChar; Len: Integer); overload; procedure SetString(var S: ShortString; Buffer: PChar; Len: Integer); overload;
When the Delphi2Cpp translator finds a call of SetString, it cannot distinguish between these declarations and will take just the first one it finds. That doesn't matter, because all three declarations have at first a variable string parameter, then a character pointer and then an integer parameter. This vague signature is all, that Delphi2Cpp needs. But later the C++ compiler can chose the right alternative for the according string type.
The implementations of the procedures for AnsiStrings and WideStrings are quite trivial More interesting is the implementation for ShortStrings:
procedure SetString(var S: AnsiString; Buffer: PChar; Len: Integer); begin (*_ S[0] = Len; if ( Buffer != NULL ) memmove( &S[1], Buffer, Len ); _*) end;
The translation with Delphi2Cpp results in:
void __fastcall SetString( AnsiString& S, char* Buffer, int Len ) { S[0] = Len; if ( Buffer != NULL ) memmove( &S[1], Buffer, Len ); }
|
This page belongs to the Delphi2Cpp Documentation |
Delphi2Cpp home Content |