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 E2313 Attribute – Known attribute cannot specify properties Reason for the Error & Solution No further information...
Delphi Compiler Error E2379 Virtual methods not allowed in record types Reason for the Error & Solution No further information...
Rodrigo , one of the long time Delphi Developer has been working on one of his personal project “Delphi IDE...