Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Code Generation/Optimization    [ Add a report in this area ]  
Report #:  134684   Status: Open
Problem with OnValidate fields type TDate on Delphi XE 7
Project:  Delphi Build #:  1
Version:    21.0 Submitted By:   Jacinto Junior
Report Type:  Crash / Data loss / Total failure Date Reported:  11/4/2015 9:48:59 AM
Severity:    Critical / Show Stopper Last Updated: 12/14/2015 6:22:14 AM
Platform:    All platforms Internal Tracking #:   72849
Resolution: None (Resolution Comments) Resolved in Build: : None
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
I apologize in advance for automated translation.

To get the value of a field of TDate type within the OnValidade method of a dataset field using .AsDateTime, .AsFloat, .AsString, .AsVariant, either IBX or DBX, IBDataSet or ClientDataSet, the return value is always 0 (zero).
Steps to Reproduce:
I apologize in advance for automated translation.

Create a field of type date in any BD, so that in IBDataset or ClientDataSet is the type TDate.

Later make reading this field in OnValidate, example:

procedure TfrmTeste.IBDataSet1MyDateValidate(Sender: TField);
begin
  if IBDataSet1MyDate.AsDateTime < Date then
    ShowMessage('Invalid date.');
end;

It may be noted that the returned value is always 0 (zero).
Workarounds
I apologize in advance for automated translation.

The cause for this problem would be:
This problem is because of the TDate type field, type TDateTime field of heritage, be handled by Delphi to the size of type Integer (4 bytes) in TDateField.GetDataSize method, but TdateTimeField.SetAsDateTime method used to assign values the field, which is not overwritten for TDate field type uses the size of the TDateTime type (8 bytes), storing the data in the last 4 bytes. The TDateTimeField.GetValue method which is internally invoked when using the .AsDateTime .AsFloat .AsString .AsVariant uses the size of type Integer (4 bytes) for reading the stored value and consequently performs the reading only the initial 4 bytes are 0 (zero).

The unit Data.DB, the TDateField.GetDataSize method should be changed to use the Tamaho the TDate type, namely:

From:

function TDateField.GetDataSize: Integer;
begin
  Result := SizeOf(Integer);
end;

To:

function TDateField.GetDataSize: Integer;
begin
  Result := SizeOf(TDate);
end;
Attachment
None
Comments

None

Server Response from: ETNACODE01