Format Function
Delphi supports "on Parameters" and dynamic arrays and variant arrays. The syntax used is similar to the set in Delphi: enclose different types of variables with two square brackets (this is too convenient ), you can also declare an array of the tvarrec type to accommodate different types of variables (see its help documentation for details)
Comparison of format function declaration
Function Format (const format: string; const ARGs: array of const): string; overload;
Extern delphi_package unicodestring _ fastcall format (const unicodestring format, tvarrec const * ARGs, const int args_high)/* overload */;
In C ++ builder, there is no syntax feature like in Delphi. The first parameter of the format function in BCB is the format function of Delphi.
Is similar (A formatted description string), and there are two parameters behind it. The second parameter is a tvarrec
Array pointer. The third parameter is the index value of the last element of the array! Because c ++
Dynamic Array syntax is not supported, and there is no such weird feature as "Open Parameters". Therefore, when you pass an array, you must also pass the array size (Format
The requirement is the index value of the last element of the array, so it is similar ). As I said earlier, tvarrec can also be used in Delphi.
Array replacement of square brackets is actually the same in nature. Of course, in C ++ builder, we do not need to declare
Tvarrec array, then assign the variable to be used for output to each element of the tvarrec array, and finally pass the tvarrec
Index of the last element of the array. In fact, we can use a pre-declared macro arrayofconst in C ++ builder to directly input the variable to be formatted and output.
Format (
"My name is % s, I'm % d years old .",
Arrayofconst ("phoenix2000", 22) // note the two parentheses
);
Fdquery1.open function declaration comparison
Procedure tfdrdbmsdataset. Open (const asql: string; const aparams: array of variant );
Fdquery1.open ('select * from TT where id =: id', [0]);
Hidesbase void _ fastcall open (const unicodestring asql, variant const * aparams, const int aparams_high)/* overload */;
Tcustomdataset. Locate function declaration comparison
Delphi
function Locate(const KeyFields: string; const KeyValues: Variant; Options: TLocateOptions): Boolean; override;
CustTable.Locate(‘Company;Contact;Phone‘, VarArrayOf([‘Sight Diver‘, ‘P‘, ‘408-431-1000‘]), [loPartialKey]);
C ++
virtual bool __fastcall Locate(const UnicodeString KeyFields, const Variant &KeyValues, TLocateOptions Options);
TLocateOptions Opts;Opts.Clear();Opts << loPartialKey;Variant locvalues[3];locvalues[0] = Variant("Sight Diver");locvalues[1] = Variant("P");locvalues[2] = Variant("408-431-1000");CustTable->Locate("Company;Contact;Phone", VarArrayOf(locvalues, 2), Opts);
Delphi variant array