Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I incorporate a TDateTimePicker in a Database

Database Programming

How do I incorporate a TDateTimePicker in a Database

by  svanels  Posted    (Edited  )
Question/Problem/Abstract:

When filling in date fields it is handy to have a calendar style look-up field. Unfortunately a "tdbCalendarlookUpBox" do not exist (unless it is a 3[sup]rd[/sup] party component), so we have to combine a TdateTimePicker component with a TdataSource

Answer:


Necessary:

1) Of course a database with a date field
2) a Form
3) a TdateTimepicker Component
4) a Tquery or Ttable
5) a Tdatasource componenent
6) optional a TdbNavigator

In my case I have a Date field named ShiftDate in my query

Events to be programmed

onDataChange, onUpdateData (datasource)

onClick (DateTimepicker)


This syncronizes the DateTimePicker with the database

procedure TForm1.DataSource1DataChange(Sender: TObject; Field: TField);
begin
inherited;
DateTimePicker1.Date := Query1SHIFTDATE.Value;
end;


This syncronizes the database with the DateTimePicker

procedure TForm1.DataSource1UpdateData(Sender: TObject);
begin
inherited;
Query1SHIFTDATE.Value; := DateTimePicker1.Date;
end;


When a date is entered the folowing procedure exports the value to the database

procedure TForm1.DateTimePicker1Click(Sender: TObject);
begin
inherited;
//disconnect handler
DataSource1.OnDataChange := nil;
// set query in edit mode
Query1.Edit;
//reconnect handler
DataSource1.OnDataChange := DataSource1DataChange;
end;

With above fragment it is possible to make your own VCL component.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top