Placeholder argument count mismatch (PC0034)
When calling StrSubstNo, Error, Message, or Confirm with a format string containing placeholders (%1, %2, #1, etc.), the number of substitution arguments must match the number of unique placeholders. A mismatch means placeholders remain unsubstituted at runtime or arguments are silently ignored.
This rule is an extension of CodeCop AA0131 and covers the gaps it misses:
- Zero-args gap: AA0131 skips validation when no substitution arguments are passed
- Confirm method: AA0131 does not cover
Confirmat all
Example (triggers PC0034)
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
TestMsg: Label 'It should give an error for this: %1', Comment = '%1=Any text';
CompleteText: Text;
begin
CompleteText := StrSubstNo(TestMsg); // PC0034: 1 placeholder but 0 arguments
end;
}
Example (no diagnostic)
codeunit 50100 MyCodeunit
{
procedure MyProcedure()
var
TestMsg: Label 'Hello %1, welcome to %2!', Comment = '%1=Name,%2=Company';
CompleteText: Text;
begin
CompleteText := StrSubstNo(TestMsg, 'World', 'Contoso'); // Correct: 2 placeholders, 2 arguments
end;
}
Notes
- The rule bails out when the format string is a
Textvariable (runtime-determined value cannot be statically analyzed) - For
Confirm, the second parameter is the default button (Boolean); substitution arguments start at position 3 - Both
%Nand#Nare recognized as placeholders - Duplicate placeholders (e.g.,
%1 appears %1 twice) count as 1 unique placeholder