Placeholder argument count mismatch
Properties
PC0034
Warning
Usage
Code Fix
Ignore Obsolete
StrSubstNo, Error, Message, and Confirm substitute placeholders (%1, %2, #1, etc.) in the format string with the arguments that follow it. The runtime does not validate that the counts match — if a label contains %1 and %2 but only one argument is passed, the output contains a literal %2 in user-facing text. Extra arguments are silently discarded.
Pass exactly as many substitution arguments as there are unique placeholders in the format string.
Example
procedure NotifyUser()
var
WelcomeMsg: Label 'Hello %1, welcome to %2!', Comment = '%1=Name,%2=Company';
begin
Message(WelcomeMsg); // Placeholder argument count mismatch [PC0034]
end;Supply the matching arguments:
procedure NotifyUser()
var
WelcomeMsg: Label 'Hello %1, welcome to %2!', Comment = '%1=Name,%2=Company';
begin
Message(WelcomeMsg, UserName, CompanyName);
end;When the diagnostic is reported
This rule extends CodeCop AA0131 to cover two gaps:
- For
StrSubstNo,Error, andMessage, the rule fires only when zero substitution arguments are passed — AA0131 already handles mismatches when at least one argument is present. - For
Confirm, the rule fires on any mismatch, since AA0131 does not coverConfirm. The second parameter ofConfirmis the default button (Boolean); substitution arguments start at the third position. - The format string must be a
Labelor a string literal.Textvariables are skipped because their value cannot be determined at compile time. - Both
%Nand#Nplaceholders are recognized. Duplicate placeholders (e.g.%1 ... %1) count as one unique placeholder.
See also
- Text.StrSubstNo(Text, Any [, Any,…]) Method on Microsoft Learn
- Dialog.Message(Text [, Any,…]) Method on Microsoft Learn
- Dialog.Error(Text [, Any,…]) Method on Microsoft Learn
- Dialog.Confirm(Text [, Boolean] [, Any,…]) Method on Microsoft Learn
- Progress Windows, Message, Error, and Confirm Methods on Microsoft Learn