Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2012-05

Parameters to Format()

4 messages · 3 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Mark Morgan Lloyd

How should I put this?

procedure TUnyokedFrontendForm.OutputWriteF(const str: widestring;
values: array of variant; fg: TColor= clBlack; bg: TColor= clDefault);
var     scratch: widestring;
begin
   scratch := Format(str, values);

As above, I get

unyokedfrontendcode.pas(354,32) Error: Incompatible type for arg no. 2:
Got "Open Array Of Variant", expected "Array Of Const"

I was caught by this one years ago, and at the time the Delphi developers I was in contact with had no easy solution.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]
Michael Van Canneyt
to Mark Morgan Lloyd
Mark Morgan Lloyd wrote 19 lines
How should I put this? procedure TUnyokedFrontendForm.OutputWriteF(const str: widestring; values: array of variant; fg: TColor= clBlack; bg: TColor= clDefault); var scratch: widestring; begin scratch := Format(str, values); As above, I get unyokedfrontendcode.pas(354,32) Error: Incompatible type for arg no. 2: Got "Open Array Of Variant", expected "Array Of Const" I was caught by this one years ago, and at the time the Delphi developers I was in contact with had no easy solution.

That's because there is no easy solution.

Format uses a different array type, they are not variants. You'll have to convert the arrays.

Michael

Unknown author
to Mark Morgan Lloyd: How should I put this? procedure TUnyokedFrontendForm.OutputWriteF(const str: widestring;…

You should do:

type
 MyVarArray = array of variant;

and then

procedure TUnyokedFrontendForm.OutputWriteF(const str: widestring;
values: MyVarArray; fg: TColor= clBlack; bg: TColor= clDefault);

Darius

Mark Morgan Lloyd wrote
How should I put

this?

procedure TUnyokedFrontendForm.OutputWriteF(const str:
widestring;
values: array of variant; fg: TColor= clBlack; bg:
TColor= clDefault);
Show quoted text 5 lines
var scratch: widestring; begin scratch
:= Format(str, values);
As above, I get
unyokedfrontendcode.pas(354,32) Error: Incompatible type for arg no. 2:
Got "Open Array Of Variant", expected "Array Of Const" I was

caught by this one years ago, and at the time the Delphi

developers I

was in contact with had no easy solution.

Mark Morgan Lloyd
to Michael Van Canneyt: That's because there is no easy solution. Format uses a different array type, they are…
Michael Van Canneyt wrote 26 lines
On Fri, 25 May 2012, Mark Morgan Lloyd wrote: > How should I put this? > > > procedure TUnyokedFrontendForm.OutputWriteF(const str: widestring; > values: array of variant; fg: TColor= clBlack; bg: TColor= clDefault); > > var scratch: widestring; > > begin > scratch := Format(str, values); > > > As above, I get > > unyokedfrontendcode.pas(354,32) Error: Incompatible type for arg no. > 2: Got "Open Array Of Variant", expected "Array Of Const" > > I was caught by this one years ago, and at the time the Delphi > developers I was in contact with had no easy solution. That's because there is no easy solution. Format uses a different array type, they are not variants. You'll have to convert the arrays.

Roughly translated: "look at the documentation and use the right parameter type" :-) Thanks, now working.

Mark Morgan Lloyd markMLl .AT. telemetry.co .DOT. uk [Opinions above are the author's, not those of his employers or colleagues]