| Here are some interesting things you can do with strings, labels etc:
Label1.Caption := 'Grace and ' + Edit1.Text;
|
| procedure TForm1.Button1Click(Sender: TObject);
var N : String; begin N := 'Tracy'; Label1.Caption := 'Grace and ' + N; end; Result = Grace and Tracy |
| procedure TForm1.Button1Click(Sender: TObject);
var I, I2, Result : Integer; begin Result := 0; I := StrToInt(Edit1.Text); I2 := StrToInt(Edit2.Text); Result := I + I2; Label1.Caption := IntToStr(I) + ' + ' + IntToStr(I2) + ' = ' + IntToStr(Result); end; |
Adding to a Memo.
Editor.Lines.Add('');//Add an empty line to the TMemo
Editor.Lines.Add('Hello world!');//Adds 'Hello world!' to a TMemo
Memo1.Lines.Add(' ' + FormatDateTime('tt ', Now));
Here are some different ways of using FormatDateTime:
| (FormatDateTime('d - m - yy ', Now)); | 16 - 11 - 98 |
| (FormatDateTime('dddddd, ' , Now)); | Monday, November 16, 1998, |
| (FormatDateTime('mm - dd - yyyy ', Now)); | 11 - 16 - 1998 |
| (FormatDateTime('d/mmm/yyyy ', Now)); | 16-Nov-1998 |
Text on a StatusBar.
This code will add text to StatusBar panels.
StatusBar1.Panels[0].Text := 'C:\Windows ';
StatusBar1.Panels[1].Text := 'Windows directory';
Showing a message. (Unit Dialogs)
[procedure ShowMessage(const
Msg: string);]
else ShowMessage('User Name Not
Found');
Adding the time to a Label with TimeToStr.
(Unit SysUtils)
[function TimeToStr(Time:
TDateTime): string;]
Label1.Caption := 'The time is ' + TimeToStr(Time);
Entering the Time using StrToTime. (Unit
SysUtils)
[function StrToTime(const S: string): TDateTime;]
procedure TForm1.Button6Click(Sender: TObject);
var TheTime : TDateTime;
begin
TheTime := StrToTime(Edit1.Text);
Label1.Caption := TimeToStr(TheTime);
end;
This code adds the full date to a Label. (Unit
SysUtils)
[function FormatDateTime(const
Format: string; DateTime: TDateTime): string;]
TheDateLabel.Caption := (FormatDateTime('dddddd. ', Now));
| How to use IntToStr and a Label. (Unit
SysUtils)
[function IntToStr(Value: Integer): string;] procedure TForm1.Button4Click(Sender: TObject);
|
| How to use StrToInt and a Label. (Unit
SysUtils)
[function StrToInt(const S: string): Integer;] procedure TForm1.Button6Click(Sender: TObject);
|
| How to use StrToIntDef and
a Label. (Unit SysUtils)
[function StrToIntDef(const S: string; Default: Integer): Integer;] procedure TForm1.Button6Click(Sender: TObject);
|
| Getting the Opened Files Name.
Label.Caption := Format('%s %s', [ExtractFileName(FileName), '']); . |
| StrToDate: (Unit SysUtils)
I found that you must use a valid date with StrToDate or an error dialog
box appears, informing you that the input is not a valid date.
procedure TForm1.Button1Click(Sender: TObject);
Here are some of the examples that I typed into Edit1. 01/03/1999
If you type only 2 numbers into Edit1 like: 1/2 - The label has 1/2/99 - This is because (According to the online help) the 2 numbers are interpreted as m/d or d/m in the current year. Any year numbers (values) between 0 and 99 are assumed to be in the
current century.
|
Putting text into a StringGrid.
{Set ColCount to 3} {StringGrid1.Cells[Col,
Row]}
{The first 3 lines will display the column headings}
StringGrid1.Cells[0, 0] := 'Name:';
StringGrid1.Cells[1, 0] := 'Town:';
StringGrid1.Cells[2, 0] := 'Country:';
StringGrid1.Cells[0, 1] := 'James'; {Row 1}
StringGrid1.Cells[1, 1] := 'Tokoroa';
StringGrid1.Cells[2, 1] := 'New Zealand';
StringGrid1.Cells[0, 2] := 'Tracy'; {Row
2}
StringGrid1.Cells[1, 2] := 'Hamilton';
StringGrid1.Cells[2, 2] := 'USA';
StringGrid1.Cells[0, 3] := 'Rachel'; {Row 3}
StringGrid1.Cells[1, 3] := 'Morecambe';
StringGrid1.Cells[2, 3] := 'England';
Tokoroa
North Island
New Zealand