N,

That worked like a charm!!!!!! Thankyou.....

At 15:43 24/08/2001 +0700, you wrote:
I would like to use the good old format function:

function Format(const Format: string; const Args: array of const): string;

Easy when you have say Format('%s blah %s', [SomeVar1, SomeVar2]);

However I have a situation where the format string is dynamic and so is the number of paramaters for the Args paramater. ie In one call I may have a format string with 12 %s and another 2 for example. Assuming that all the arguments that would be passed for Args are strings is there any way to build the args paramater dynamically. I tried a dynamic array but that did not seem to do the trick. Has anyone got any pointers or can someone tell me how to do this easily another way perhaps?
the "array of const" that is the second parameter to Format
is really an array of TVarRecs
 
so how about:
 
 
procedure TForm1.Button1Click(Sender: TObject);
var
    args: array of TVarRec;
    alen:integer;

 
    procedure addString(s:string);
    begin
        alen:=alen+1;
        setlength(args,alen);
        with args[alen-1]
        do begin
            VType := vtPChar;
            VPChar := PChar(s);
        end;
    end;
       
begin
    alen:=0;   
    addString('Donovan');
    addString('what you');
    addString('mind');
    ShowMessage (format('%s is this %s had in %s?',args));
end;

 
 
-ns

-- Donovan
----------------------------------------------------------------------
Donovan J. Edye [
www.edye.wattle.id.au]
Namadgi Systems [
www.namsys.com.au]
Voice: +61 2 6285-3460
Fax: +61 2 6285-3459
TVisualBasic = Class(None);
Heard just before the 'Big Bang': "...Uh Oh...."
----------------------------------------------------------------------
GXExplorer [
http://www.gxexplorer.org] Freeware Windows Explorer
replacement. Also includes freeware delphi windows explorer components.
----------------------------------------------------------------------

Reply via email to