How to build the SysUtils.Format string function in Delphi?
Posted
by
Sam
on Stack Overflow
See other posts from Stack Overflow
or by Sam
Published on 2013-10-23T03:25:44Z
Indexed on
2013/10/23
3:53 UTC
Read the original article
Hit count: 123
delphi
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.
© Stack Overflow or respective owner