delphicaptioncontrol-characterstlabel

Is the behaviour of the tab character in a Delphi TLabel caption defined?


If I put tab characters into a string and then assign the Caption property of a label from the string what do the tab characters do?

CR characters cause a return, which is useful for displaying a multi-line caption. Tab characters do seem to perform some sort of tabbing action - I'm wondering if this behaviour is defined or predictable. (I guess the behaviour is determined by Windows, not Delphi).


Solution

  • If you put tab characters in a TLabel.Caption, the Caption contains tab characters.

    How the tab character is displayed depends on the font you use and Windows itself. A quick test in XE, for instance, on Win7 displays spacing appropriate for tab characters (approximately 8 spaces, in a non-proportional font).

    Here's my test. Drop three labels on a form, and add this to the form's OnCreate event:

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Label2.Left := Label1.Left;
      Label3.Left := Label2.Left;
      Label1.Caption := 'Some text'#9'Some text'#9'More text';
      Label2.Caption := Label1.Caption;
      Label3.Caption := Label1.Caption;
    end;
    

    Here's the output:

    Sample label output