TDBAdvSmoothDatePicker

I save the record and the "Date" field in the table is null. I tried:

  1. Date is set automatically
  2. I leave the component
  3. I select a date in the calendar and leave the component

I have to manually overwrite the date and leave the component. This is the only option.
I don't know if this is standard behavior. It's certainly not what I expect.

One solution is

procedure TfrmsubTeamStadium.dbdatpcDateFrom05Change(Sender: TObject);
begin
if fdtbTeamStadium.State in [dsInsert, dsEdit] then
fdtbTeamStadium.FieldByName('DATEFROM').AsDateTime := dbdatpcDateFrom05.Date;
end;

I'm not sure what exactly you mean.
I cannot see an unexpected behavior so far.

Changing the date from the TDBAdvSmoothDatePicker puts the dataset in edit state and updates the Field date with the date selected from the TDBAdvSmoothDatePicker. When the active record is changed or the dataset.Post is done, this changed date from the TDBAdvSmoothDatePicker is stored in the dataset.

What exactly do you see different? How exactly can we reproduce this?

When the active record is changed or the dataset.Post is done, this changed date from the TDBAdvSmoothDatePicker is stored in the dataset.

Oh, there's the problem. In my case, it's too late.
I do a data check before running the Post. For all your DB components it works. Only with this one is DataSet.FieldDate = null.
I've moved the code shown here to OnValueValidate. I'll stick with this solution.
Thanks!

For completeness. I had to modify the function a bit with respect to the component behavior.

var Dp := TDBAdvSmoothDatePicker(Sender);
if not IsValid or (Dp.Date < FMinDate) then Exit;

if (Dp.DataSource.DataSet.State in [dsInsert, dsEdit]) then
Dp.DataSource.DataSet.FieldByName(Dp.DataField).AsDateTime := Dp.Date;

Please, what does this nonsensical behaviour mean?
IsValid is always TRUE

Should I understand from this screenshot what exactly you do? To begin with, how is the date formatted in the control and what are your machine date/time formatting settings. The most likely reason for this exception is a mismatch between how the date is in the TDBAdvSmoothDatePicker and the expected format based on your OS date/time format settings. Check this and make sure these match.

Yeah. I was convinced of that :wink:
We go step by step.
AllowNumberNullValue = True
The edit field is empty.
1st image
I enter day = 6 Value '6' IsValid = True Date = 12/30/1999
2nd image. The test for IsValid has been run
day = 6 Value '6' IsValid = True Date = 5. 1. 1999 ????
3rd image
I enter month = 4
day = 5 month = '' Value '5.. 1900' IsValid = True Date = 12/30/1999
4th picture
Test for IsValid
day = 5 month = '' Value '5.. 1900' IsValid = True Date = 8/17/2023 20:31:58
The next command raises an exception. Why?

Do you consider this normal?
Just put the component on the form, connect to the DB and define the OnValueValidate function. And you can try it.
I don't know of any description of it anywhere. If there is, where can I find it?

procedure TAppearance.DBDateValueValidate(Sender: TObject; value: string; var IsValid: Boolean); //FI:O801
begin
var Dt: TDateTime;
var Dp := TDBAdvSmoothDatePicker(Sender);

if not TryStrToDateTime(value, Dt) then
begin
Dp.Text := Value;
Exit;
end;

if (Dt < FMinDate) then Exit;

if (Dp.DataSource.DataSet.State in [dsInsert, dsEdit]) then
Dp.DataSource.DataSet.FieldByName(Dp.DataField).AsDateTime := Dt;
end;

The TryStrToDateTime function didn't excel either! :rage:
value = '6'
if not TryStrToDateTime(value, Dt) then
return: Dt = 30. 12. 1899 6:00:00

It looks like I have to do my own evaluation of the text :sob:

It looks like the condition at the beginning of the function "if Length(value) < 8 then Exit;" solves it

Essential missing information to begin with:
You must have set ShowError = true to get what you describe here.

For OnValueValidate, IsValid is set internally to true by default, your application code needs to set IsValid , that's why it is a VAR parameter

When you set ShowError = true, it is your code in OnValueValidate that will determine whether the input in the control is considered valid or not and when invalid, it will be displayed in the error color.

IsValue = False
Write 6
image
I leave the component
image
Why is there a full date? There must be only 6! I can set the focus back to the component after all.
I'll stick to my solution. It works for me as I need it to.
Except if I don't have a full date and I leave the component. It always fills it in. I can't override that.

procedure TAppearance.DBDateValueValidate(Sender: TObject; value: string; var IsValid: Boolean); //FI:O801
begin
  var Val := Trim(value);
  if (Length(Val) < Idx8) then Exit;

  var Dt: TDateTime;
  var Fs := TFormatSettings.Create;
  if not TryStrToDateTime(Val, Dt, Fs) then Exit;

  if Dt < MinDate then
  begin
    ShowMessage('The date must be higher than ' + DateToStr(Dt));
    Exit;
  end;

  var Dp := TDBAdvSmoothDatePicker(Sender);

  if (Dp.DataSource.DataSet.State in [dsInsert, dsEdit]) then
    Dp.DataSource.DataSet.FieldByName(Dp.DataField).AsDateTime := Dt;
end;

I considered that the best and easiest thing to do would be to change the way I check the date. Don't work with DataSet, but only with Calendar.

I found strange behaviour.

DataSet.Edit;
I'll enter the date. The cursor remains in the edit box.
DataSet.Post;
Transaction.Commit;
DataSet.State = dsEdit - why?
If I leave the component first, everything is OK.

Please explain.

I cannot reproduce this based on the limited information provided.

Test code:

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
  adotable1.Post;

  if ADOTable1.State = dsEdit then
    outputdebugstring('still in edit?');
end;

-> the message is not sent

This behaviour is only at TDBAdvSmoothDatePicker. For all others is OK

I tested this with TDBAdvSmoothDatePicker as this is what this thread is about

Again, I misread. Let's leave it at that. The user will have to leave the DatePicker.

Nevertheless, I continue :sob:
I've figured out when the State change occurs. I hope the pictures will explain.
ACont is the panel on which the TDBAdvSmoothDatePickers are.

Panel.Enabled = True
Change
Panel.Enabled = False will trigger the DataSet.State change

In the picture you can see the solution. I would be most happy if it disappeared

I propose you isolate this and send a sample source test project + step by step information to reproduce the problem.

I tried it in a simple project. There the problem did not occur. I suspect the form itself. Occasionally over a long period of time I get some corruption.
Who knows?