The string length is automatically set but sometimes you want to change the length yourself. That’s because sometimes you have to have the same length of a string every time (when saving to binary files). You can always use the string[n] (ShortString) type but their maximum length is 256 characters.
!!Note: You CAN NOT set the length of string constants.
var
sString: string;
...
{ This code sets the string length to 512 characters }
SetLength(sString, 512);
Tags: code, constant, Delphi, free, length, open source, pchar, set, source code, sources, string, tip, trick, variable
Merlin’s Delphi Forge
Leave a comment