Title: How to create an notice calendar for your application
Question: Your application needs a memory-table to keep important notices.
Answer:
create Table1 (e.g. MyNotice.db) with this fields:
OK Char 1 *
MDate D *
MTime T *
Notice A 100
...
place this Objects on Form1
Table1 MyNotice.db
DataSource1 to Table1
DBGrid1 to DataSource
with the following events:
DBGrid1CellClick
DBGrid1ColEnter
DBGrid1ColExit
DBGrid1DrawColumnCell
set the Font for Field 'OK' to Wingdings
Field 'MDate' is set visible/invisible by
events onColEnter / onColExit
TMonthCalendar Name: MC
with onClick to MCClick
place it in the DBGrid1 top to the Field Notice
ToolBar with
SpeedButton Name: FilterBtn
with the onClick event to FilterBtnClick
DBNavigator1
with the onClick event to DBNavigator1Click
const
OkFlag = ''; // small hook from Font Wingdings
NotOkFlag = ' '; // empty
procedure TForm1.FormCreate(Sender: TObject);
begin
Table1.open;
end;
procedure TForm1.FormCloseQuery(Sender: TObject;
var CanClose: Boolean);
begin
if (Table1.State in [dsEdit, dsInsert]) then Table1.post;
Table1.close;
end;
// make flip/flop between OkFlag and NotOkFlag
procedure TForm1.DBGrid1CellClick(Column: TColumn);
begin
if (column.Fieldname = 'OK') then begin
Table1.Edit;
if (Table1.FieldByName('OK').AsString '') then
Table1['OK'] := NotOkFlag
else
Table1['OK'] := OkFlag;
Table1.post;
DBGrid1.SetFocus;
DBGrid1.SelectedField := Table1.FieldByName('Notice');
end;
end;
// make the selected Row/column ligth-blue
procedure TForm1.DBGrid1DrawColumnCell(Sender: TObject;
const Rect: TRect; DataCol: Integer; Column: TColumn;
State: TGridDrawState);
begin
if gdSelected in State then
begin
DBGrid1.Canvas.Font.Color := clWhite;
DBGrid1.Canvas.Brush.Color := clBlue;
end;
DBGrid1.DefaultDrawColumnCell(Rect, DataCol, Column, State);
end;
// set default date and time for new records
procedure TForm1.DBNavigator1Click(Sender: TObject;
Button: TNavigateBtn);
begin
if (Button = nbInsert) then begin
with Table1 do begin
append;
edit;
FieldValues['MDate'] := Date;
FieldValues['MTime'] := Time;
DBGrid1.SetFocus;
post;
edit;
DBGrid1.SelectedField := Table1.FieldByName('MDate');
MC.visible := True
end;
end;
end;
// set/reset Table-filter
procedure TForm1.FilterBtnClick(Sender: TObject);
begin
if (Table1.Filter = '') then
Table1.Filter := 'OK = '''''
else
Table1.Filter := '';
end;
// get the selected date from the TMonthCalendar
// and set it into the current record
procedure TForm1.MCClick(Sender: TObject);
begin
Table1.edit;
Table1['MDate'] := MC.Date;
Table1.post;
end;
// at column 'MDate'-exit set TMonthCalendar invisible
procedure TForm1.DBGrid1ColExit(Sender: TObject);
begin
if (DBGrid1.SelectedField.DisplayLabel = 'MDate') then
MC.Visible := False;
end;
// at column 'MDate'-enter set TMonthCalendar visible
procedure TForm1.DBGrid1ColEnter(Sender: TObject);
begin
if (DBGrid1.SelectedField.DisplayLabel = 'MDate') then
MC.visible := True;
end;
end.
Regards
Kurt