{ list box OnClick event handler }
procedure TForm1.ListBox1Click(Sender: TObject);
begin
{ Items property, stores the values in the list, it is an object of type TString, so the list can be managed using the methods discussed in the Sorter example }
{ ItemIndex property, is the ordinal number of the selected item in the list }
DisplayDayOfWeek(ListBox1.Items[ListBox1.ItemIndex]);
end;
{ translates the input date to a DOW }
procedure TForm1.DisplayDayOfWeek(DOWText : string);
var
DayValue : Integer;
DTValue : TDateTime;
DayName : String;
begin
{ cast the string to a datetime - if this doesn't work, an exception will be raised and caught below }
try
DTValue := StrToDate(DOWText);
{ get the integer dow and translate to a string }
DayValue := DayOfWeek(DTValue);
case DayValue of
1: DayName := 'Sunday';
2: DayName := 'Monday';
3: DayName := 'Tueday';
4: DayName := 'Wednesday';
5: DayName := 'Thursday';
6: DayName := 'Friday';
7: DayName := 'Saturday';
else
DayName := 'Error'
end;
{ set the label caption with the date and dow }
Label4.caption := DOWText+ ' is a ' + DayName;
except
{ on date conversion error, display message }
on EConvertError do
Label4.Caption := 'Invalid date';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
DisplayDayOfWeek(MEdit1.Text);
end;
procedure TForm1.FileListBox1Change(Sender: TObject);
begin
{ this procedure will display the current selected file name on a Label }
if FileListBox1.FileName = '' then
label5.Caption := 'No file selected'
else
label5.Caption := Filelistbox1.FileName;
{ components used are all under the Win 3.1 control tab }
{ DirectoryListBox = FileList := FileListBox
DriveComboBox = DirList := DirectoryListBox
FilterComboBox := FileListBox
FileListBox
}
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
{ will call the Printer Setup Dialog under the Dialogs control tab }
printersetupdialog1.Execute;
end;
|