Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delphi, label max characters

Tags:

label

delphi

TLabel has its maximum characters 255(ShortString) but I need more than that. What should I use?

like image 938
hs2d Avatar asked Dec 21 '22 14:12

hs2d


1 Answers

No, there is no limit. I just tried to use a string with 1223 characters as the caption of a TLabel, and that works. In code, however, a string literal cannot exceed 255 characters. But that is not a problem. Just do

Label1.Caption := 'This is a test. This is a test. This is a test.' + 
  'This is a test. This is a test. This is a test. This is a test.' +
  'This is a test. This is a test. This is a test. This is a test.' +
  'This is a test. This is a test. This is a test. This is a test.' +
  'This is a test. This is a test. This is a test. This is a test.' +
  'This is a test. This is a test. This is a test. This is a test.' +
  'This is a test. This is a test. This is a test. This is a test.';

You can make the caption as long as you wish, but a single string literal, the text in the source code between ' and ', cannot exceed 255 characters. To construct a longer string, use the string concatenation operator (+) to concatenate shorter string literals.

like image 184
Andreas Rejbrand Avatar answered Jan 01 '23 22:01

Andreas Rejbrand