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.