Recent

Author Topic: [SOLVED] TDBDateTimePicker???  (Read 1122 times)

1HuntnMan

  • Full Member
  • ***
  • Posts: 186
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
[SOLVED] TDBDateTimePicker???
« on: February 20, 2024, 10:51:57 pm »
I am attempting to use DBDateTimePicker on an Appointments form.  I set up the form and testing, all okay except the TDBDateTimePicker.  What's with the Time, it defaults to 12:00 AM. You can change the date and time but when you post/save the time part goes back to 12:00 AM.  Is there a property that I'm not setting correctly?
« Last Edit: February 21, 2024, 11:00:40 pm by 1HuntnMan »

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: TDBDateTimePicker???
« Reply #1 on: February 21, 2024, 10:07:06 am »
You must do better than this if you expect help.
You didn't say anything about your environment. Not even which database system you are using!
Read: https://wiki.freepascal.org/Forum

Works well here - Lazarus 3.1 fixes branch, SQLDb, FPC 3.2.2, Firebird 3, Windows 10.

Check your field data type - is it date or datetime (called timestamp in Firebird)?

If there is someone with a better crystal ball model than mine...


wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TDBDateTimePicker???
« Reply #2 on: February 21, 2024, 12:53:45 pm »
Yes, big crystal ball needed here... But I guess he is declaring the field type as ftDate (which removes the fractional part of the date/time numbers) and uses the DBDateTimePicker with property Kind = dtkDateTime to display both date and time (but the time part has been removed by the field type ftDate).

Solution: declare the field type as ftDateTime when you want both data and time.

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
Re: TDBDateTimePicker???
« Reply #3 on: February 21, 2024, 01:23:11 pm »
And going by his other threads in the Database-Section, i'd hazard a guess, it's DBase....
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

1HuntnMan

  • Full Member
  • ***
  • Posts: 186
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateTimePicker???
« Reply #4 on: February 21, 2024, 03:51:28 pm »
It's not a multi-user system, it's a photography application I'm writing for a fellow photographer. So, I am using TDbf/Datasets, Level 7.  When I designed the Appointments table, I used My Dbf Studio to setup the table and the rest of the tables.  I added the APPTDTIME field as Date/Time with an index. But, checking awhile ago with My Dbf Studio, the field is just designed as Date.  I thought I set it to Date/Time and not just Date.  So, changed it to Date/Time, deleted the index and recreated it and restructured the table.  Then, went back to check and My Dbf Studio is NOT saving as Date/Time it's reverting to just Date.  Deleted the Index and went back 3 times and changed the field type to Date/Time and restructured the table. But, My Dbf Studio isn't saving as Date/Time no matter how many times I change it back to field type Date/Time.

I also put in a Setup menu option with a procedure to create the whole Database (tables and indexes). Here's the code for the Appointments table.  I'm going to run this and recreate just the Appointments table and indexes. Then test again and see if that fixes the issue. My Dbf Studio isn't working right on this issue.  If this fixes the issue, then I'll check to see if there's an update to My Dbf Studio.

Code for creating the Appointments table and indexes:
Code: Pascal  [Select][+][-]
  1.   SpdBtnPMSDataRebuild.Enabled:= False;
  2.   PrgrsBarTableRebld.Position:= 5;
  3.   ForceDirectories('PMS Data'); { Note: PMS Database Directory = PMS Data }
  4.   if FileExists('Appointments.dbf') then
  5.     DeleteFile('Appointments.dbf');
  6.   Appointments := TDbf.Create(nil);
  7.   try
  8.      // ForceDirectories('PMS Data');
  9.      { Use the relative path to the "PMS Data" directory }
  10.      Appointments.FilePath := 'PMS Data' + DirectorySeparator;
  11.      { Use Visual dBase VII compatible tables for Lazarus }
  12.      Appointments.TableLevel:= 7;
  13.      Appointments.Exclusive:= True;
  14.      Appointments.TableName:= 'Appointments.dbf';
  15.      with Appointments.FieldDefs do begin
  16.        PrgrsBarTableRebld.Step:= 10;
  17.        PrgrsBarTableRebld.Position:= 10;
  18.        Add('APPTID', ftAutoInc, 4, True);
  19.        Add('APPTDATETIME', ftDateTime, 8, True); // Do I leave the field length empty here???
  20.        Add('CNTKLNAME', ftString, 15, True);
  21.        Add('CNTKFNAME', ftString, 15, True);
  22.        Add('CNTKMI', ftString, 1, True);
  23.        Add('CLIENT', ftString, 25, True);
  24.        Add('PHONE', ftString, 15, True);
  25.        Add('EMAIL', ftString, 25, True);
  26.        Add('ADDRESS', ftString, 30, True);
  27.        Add('CITY', ftString, 25, True);
  28.        Add('STATEPROV', ftString, 2, True);
  29.        Add('POSTALCODE', ftString, 10, True);
  30.        Add('DIRECTIONS', ftMemo, 10, True);
  31.        Add('NOTES', ftMemo, 10, True)
  32.      end;
  33.      Appointments.CreateTable;
  34.      Appointments.Open;
  35.      PrgrsBarTableRebld.Position:= 30;
  36.      {Add the primary index}
  37.      Appointments.AddIndex('APPTNO','APPTID',[ixPrimary]);
  38.      {Add a secondary indexes}
  39.      Appointments.AddIndex('APPTDTIME','DTOS(APPTDATETIME)',[]);
  40.      Appointments.AddIndex('CNTKNAME','CNTKLNAME+CNTKFNAME+CNTKMI',
  41.        [ixExpression, ixCaseInsensitive]);
  42.      Appointments.AddIndex('CLIENT','CLIENT',[ixCaseInsensitive]);
  43.      Appointments.Close;
  44.    finally
  45.      Appointments.Free;
  46.    end;
  47.  

Zvoni

  • Hero Member
  • *****
  • Posts: 2327
One System to rule them all, One Code to find them,
One IDE to bring them all, and to the Framework bind them,
in the Land of Redmond, where the Windows lie
---------------------------------------------------------------------
Code is like a joke: If you have to explain it, it's bad

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TDBDateTimePicker???
« Reply #6 on: February 21, 2024, 05:04:18 pm »
This must be a bug in MyDbfStudio then since the following minimal demo shows that the time part of a ftDateTime field is conserved when the table has been created with Tablelevel 7, 25 or 30

1HuntnMan

  • Full Member
  • ***
  • Posts: 186
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateTimePicker???
« Reply #7 on: February 21, 2024, 05:24:59 pm »
Well, my Setup procedure fixed it, so, it's a My Dbf Studio issue.  Thanks all for your suggestions and help.
1HuntnMan aka Donald

1HuntnMan

  • Full Member
  • ***
  • Posts: 186
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateTimePicker???
« Reply #8 on: February 21, 2024, 05:30:59 pm »
WP, do you mean that if in My Dbf Studio, I create a table as Level 7, it supports DateTime when you said the time part is conserved, i.e. it supports DateTime and not just Date?

I created all these tables in this app originally with My Dbf Studio and when you create or restructure it's labeled as Table Level 7.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TDBDateTimePicker???
« Reply #9 on: February 21, 2024, 06:22:31 pm »
I mean: In the test application of my previous post the dbf file contains an ftDateTime field (which contains date and time part). And when i load it into MyDBFStudio that field is correctly reckognized.

However, when I use MyDBFStudio to create a dbf Tablelevel 7 file with an ftDateTime field this field type is not stored correctly. It is only stored as an ftDate field. This can be seen when I load that file into a small application just reading basic field information:

Code: Pascal  [Select][+][-]
  1. program dbf_info;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. uses
  6.   SysUtils, Classes, dbf, dbf_common, db, LazFileUtils;
  7.  
  8. var
  9.   Dbf1: TDbf;
  10.   i: Integer;
  11.  
  12. begin
  13.   if ParamCount = 0 then
  14.   begin
  15.     WriteLn('Syntax: dbf_info dbffile');
  16.     Halt;
  17.   end;
  18.  
  19.   Dbf1 := TDbf.Create(nil);
  20.   try
  21.     Dbf1.FilePath := ExtractFilePath(ParamStr(1));
  22.     Dbf1.TableName := ExtractFileName(ParamStr(1));
  23.     Dbf1.Open;
  24.     WriteLn(  '   dbf file: ', ParamStr(1));
  25.     WriteLn;
  26.     WriteLn(  'Table Level: ', Dbf1.TableLevel);
  27.     WriteLn(  'Fields:');
  28.     for i := 0 to Dbf1.FieldCount-1 do
  29.       WriteLn('             ', i,
  30.         ': "', Dbf1.Fields[i].FieldName,
  31.         '"; type ', Dbf1.Fields[i].DataType,
  32.         '; size ', Dbf1.Fields[i].Size,
  33.         '; required ', Dbf1.Fields[i].Required);
  34.   finally
  35.     Dbf1.Free;
  36.   end;
  37. end.

This means there is some issue in MyDBFStudio with table creation.

1HuntnMan

  • Full Member
  • ***
  • Posts: 186
  • From Delphi 7 to Lazarus
    • NewFound Photo Art
Re: TDBDateTimePicker???
« Reply #10 on: February 21, 2024, 11:00:14 pm »
Yup, thanks WP.

wp

  • Hero Member
  • *****
  • Posts: 11916
Re: TDBDateTimePicker???
« Reply #11 on: February 23, 2024, 02:17:53 pm »
This means there is some issue in MyDBFStudio with table creation.
Found some issues in handling the TableLevel in MyDBFStudio, and an inconsistency in the DbfVersion used by the sourceforge TDbf in comparison with that from fpc3.2.2. Therefore I switched back to the TDbf component provided by fpc 3.2.2, and together with the fixed TableLevel issue the ftDateTime fields are no longer converted to ftDate. This should fix your issue.

To get a new version of the program, download its source from my github (https://github.com/wp-xyz/MyDBFStudio/tree/master, green "Code" button, then "Download ZIP") and compile it with any Lazarus version after 2.0; additionaly libaries are not required.

 

TinyPortal © 2005-2018