Главная страница | назад





Article #25683: Using Control Characters With Delphi

Problem:
An example of using control characters with Delphi to format text displayed in a label
component.
Solution:
Using Control Characters With Delphi
Wayne Shaddock
?1998
1) Open a new project:
From the 'File' menu select New Application
2) Place two buttons on the form:
From the Standard tab of the Component Pallet double-click
the button icon twice
3) Place two labels on the form:
From the Standard tab of the Component Pallet double-click
the label icon twice
4) Change the captions of the two buttons:
Click Button1 to select it and change the 'Caption'
property to 'No Control Character' (without the single quotes)
Click Button2 to select it and change the 'Caption'
property to 'Control Character' (without the single quotes)
5) Change the captions of the two labels:
Click Label1 to select it and change the 'Caption'
property to 'Without Carraige Return Control Character'
(without the single quotes)
Click Label1 to select it and change the 'Caption'
property to 'With Carraige Return Control Character'
(without the single quotes)
6) Code the Event Handler for Button1:
Double-click Button1 to invoke the Event Handler. Declare a
variable declaration section by typing the keyword 'var' between
the keyword 'procedure' and 'begin'.
Declare a string variable by typing the following below the
keyword 'var':
S1 : string;
Type the following code in the body of the procedure:
S1 := 'This is a string with no carraige return control character.';
Label1.Caption := S1;
7) Code the Event Handler for Button2:
Following the example for the first button enter the code for the
event handler as follows:
procedure TForm1.Button2Click(Sender: TObject);
var
S1, S2 : string;
begin
S1 := 'This is a string with';
S2 := 'a carraige return control character.';
Label2.Caption := S1 + #10 + S2;
end;
9) Compile and run the project: press the F9 key.
Pressing the button labeled 'No Control Character' results in the
first label displaying a text string as a single line. Pressing
the other button results in a text string being displayed in
the second label on two lines because of the inclusion of the
control character '#10' in the code for Button2's event handler.

Last Modified: 23-OCT-00