* * *

Author Topic: TDBF - Issue with TTimestamp and TDateTime Get Function  (Read 605 times)

dparnaby

  • New member
  • *
  • Posts: 7
TDBF - Issue with TTimestamp and TDateTime Get Function
« on: April 20, 2017, 11:35:10 am »
I use TDBF extensively in my Accounting project front end to firebird .

The assignment  to "result"  as below is not robust as it will reject a Tdatetime that has zero time element.
******************************************************************************************************************
 Result := (Unaligned(PInteger(Src)^) <> 0) and (Unaligned(PInteger(PChar(Src)+4)^) <> 0);
******************************************************************************************************************


SEE ALTERED SOURCE BELOW- THERE  IS A ROBUSTNESS ISSUE

as the function GetFieldDataFromDef requires  a time value other than zero to process correctly where FDateTimeHandling is set to dtDateTime  .

Regards - David Parnaby - Durban  :(
***************************************************************************************************************

Source DBF_DBFFile starts line  1697

function TDbfFile.GetFieldDataFromDef(AFieldDef: TDbfFieldDef; DataType: TFieldType;
  Src, Dst: Pointer; NativeFormat: boolean): Boolean;
    '@':
      begin
        {*********************in house amendments***********************}
        if FDateTimeHandling = dtBDETimeStamp then
          begin
            Result := (Unaligned(PInteger(Src)^) <> 0) and (Unaligned(PInteger(PChar(Src)+4)^) <> 0);
            if Result and (Dst <> nil) then
            begin
              SwapInt64BE(Src, Dst);
                date := BDETimeStampToDateTime(PDouble(Dst)^);
             SaveDateToDst;
             end;
        end else
        if FDateTimeHandling = dtDateTime then
        begin
       //-Takenout->
    ******************************************************************************************************************
//    Result := (Unaligned(PInteger(Src)^) <> 0) and   (Unaligned(PInteger(PChar(Src)+4)^) <> 0);
   ******************************************************************************************************************
          if  (Dst <> nil) then
          begin
            SwapInt64BE(Src, Dst);
             { zero date can cause exceptions }
             if Unaligned(PInteger(Src)^) =0 then
               date:=1 else
                 date := PDateTime(Dst)^;
           SaveDateToDst;
          end;
       end;
      {*********************in house amendments***********************}


« Last Edit: April 20, 2017, 12:09:55 pm by dparnaby »

Handoko

  • Hero Member
  • *****
  • Posts: 1423
  • My goal: build my own game engine using Lazarus
Re: TDBF - Issue with TTimestamp and TDateTime Get Function
« Reply #1 on: June 07, 2017, 08:51:11 pm »
Hello dparnaby.

Can you please provide us the compilable source for us to try? You can write a demo project that shows the issue. Zip them (except the executable and lib folder) and send it to this forum. Please also provide the sample data.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus