How to build the SysUtils.Format string function in Delphi?
- by Sam
If I have the following Delphi code
type TFormatArgs = array of TVarRec;
procedure DelphiGodsGiveMeTheAnswerPrettyPlease;
var
iMyAge: integer;
iMyIQ: integer;
sCode: string;
sText: string;
begin
iMyAge := 5;
iMyIQ := -5;
sCode := 'Format(''My age is %d and my IQ is %d'', [iMyAge, iMyIQ])';
sText := FormatThis(sCode, iMyAge, iMyIQ);
end;
function FormatThis(sFormatCode: string; iVar1: integer; iVar2: integer): string;
var
sFormatString: string;
arFormatArgs: TFormatArgs;
begin
sFormatString := GetFormatString(sFormatCode); // I can implement this function
arFormatArgs := ConstructFormatArgs(iVar1, iVar2); // NEED HELP HERE!
result := SysUtils.Format(sFormatString, arFormatArgs);
end;
How can I implement my ConstructFormatArgs function in Delphi (not Assembly)? I'm afraid the assembly code in SysUtils.WideFormatBuf is just a little bit beyond my comprehension skills! Any ideas? I'm seeking divine assistance. Even if you can contribute just a little hint here and there on how to improve it or help me progress with this exercise. TIA.