INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Database Programming

How do I incorporate a TDateTimePicker in a Database by svanels
Posted: 7 Apr 03

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 3rd 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.

Back to Embarcadero: Delphi FAQ Index
Back to Embarcadero: Delphi Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close