* * *

Author Topic: TDBF - Issue with TTimestamp and TDateTime Get Function  (Read 138 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 »

 

Recent

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