ToDoList : Questions about dates

Hi everyone.
I can't find a way to reset dates (creationdate, duedate,completiondate) and have the nulldate string shown at runtime.

If a user click on complete, set completiondate if empty, works fine, but if user click for uncheck complete...

procedure TF_Eloi.TD_IndispoCompleteClick(Sender: TObject; ItemIndex: Integer);
begin
with TD_indispo.Items[ItemIndex] do
begin
   if complete = true then
  begin
       if DateToStr(Completiondate) <> Td_Indispo.nulldate then
        Completiondate := now;
        status := tscompleted;
  end
  else
  begin
    //    Reset date + null string
  end;
end;

end;

Can anyeone help me ?

Best regards.

If you want to set a null data, you'd need to use:
dataset.FieldByName('completiondate').AsString := '';

Do this for example from the DBTodoList OnEditDone event as this needs to be set after editing stopped.

Hi Bruno.
I try this (no DB),

procedure TF_Eloi.TD_IndispoCompleteClick(Sender: TObject; ItemIndex: Integer);
begin
  with TD_Indispo.Items[ItemIndex] do
  begin
    if complete = true then
    begin
      if DateToStr(Completiondate) = TD_Indispo.nulldate then
        Completiondate := now;
      status := tscompleted;
    end
    else
    begin
      // Reset date + null string
      completiondate:=strtodate(''); // dataset.FieldByName('completiondate').AsString := '';


    end;
  end;

end;

Result is an error
Capture d’écran 2022-10-24 180944

I tried this with success :

procedure TF_Eloi.TD_IndispoCompleteClick(Sender: TObject; ItemIndex: Integer);
var
resetdate:double;
begin
resetdate:=0;
  with TD_Indispo.Items[ItemIndex] do
  begin
    if complete = true then
    begin
      if DateToStr(Completiondate) = TD_Indispo.nulldate then
        Completiondate := now;
      status := tscompleted;
    end
    else
    begin
      // Reset date + null string
      completiondate:=resetdate;
    end;
  end;
end;

Maybe it will be usefull for someone else.
:grinning:

Useful tip! Many thanks for sharing.