HomeDelphiDelphi Error – W1014 String constant truncated to fit STRING%ld

Delphi Error – W1014 String constant truncated to fit STRING%ld

Delphi Compiler Error

W1014 String constant truncated to fit STRING%ld

Reason for the Error & Solution

A string constant is being assigned to a variable which is not large enough to contain the entire string. The compiler is alerting you to the fact that it is truncating the literal to fit into the variable. -W

program Produce;
(*$WARNINGS ON*)

  const
    Title = 'Super Galactic Invaders with Turbo Gungla Sticks';
    Subtitle = 'Copyright (c) 2002 by Frank Haversham';

  type
    TitleString = String[25];
    SubtitleString = String[18];


  var
    ProgramTitle : TitleString;
    ProgramSubtitle : SubtitleString;

begin
  ProgramTitle := Title;
  ProgramSubtitle := Subtitle;
end.

The two string constants are assigned to variables which are too short to contain the entire string. The compiler will truncate the strings and perform the assignment.

program Solve;
(*$WARNINGS ON*)

  const
    Title = 'Super Galactic Invaders with Turbo Gungla Sticks';
    Subtitle = 'Copyright (c) 2002';

  type
    TitleString = String[55];
    SubtitleString = String[18];


  var
    ProgramTitle : TitleString;
    ProgramSubtitle : SubtitleString;

begin
  ProgramTitle := Title;
  ProgramSubtitle := Subtitle;
end.

There are two solutions to this problem, both of which are demonstrated in this example. The first solution is to increase the size of the variable to hold the string. The second is to reduce the size of the string to fit in the declared size of the variable.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...