1 (edited by Zlaya 2020-09-19 06:25:05)

Topic: Do something if the preset date has expired

I want to add the piece of code to my script that will do something (make invisible a TableGrid1 , dissable button1 , show message or clear the table) if the preset date has expired.
Any suggestion?

Re: Do something if the preset date has expired

Without knowing exactly what you are doing my thoughts are:


Check the date(now) with the preset date. 


IF date(now) is  > than preset date  THEN
  component.visible := false; 


Component can be tablegrid, button etc.


To disable a component write


component.enabled := false;


or


ShowMessage('Date has expired');

On a clear disk you can seek forever

Re: Do something if the preset date has expired

Thanks CDR,

How should look like that part of code for DataTimePicker1 ?
Probably in Form1_OnShow event?
Thanks in advance.

4 (edited by derek 2020-09-22 23:28:39)

Re: Do something if the preset date has expired

Hi Zlaya, CDB,
You could try something like the attached (possibly overkill for your requirements, but it allows you to change the pre-set date and it checks immediately if the pre-set date has expired rather than only when you start the program).  If it has expired, it shows a message, makes the tablegrid invisible and disables button1 (just as examples of the sort of things you might do).
Derek.

Post's attachments

Attachment icon presetdate2.zip 336.59 kb, 296 downloads since 2020-09-22 

Re: Do something if the preset date has expired

Thanks for the replies, but I would need something very similar to that.
The DataTimePicker1 should not be visible.
I should add to the code the preset fixed date and if it is expired, do something.
I don't know how to do it.

Re: Do something if the preset date has expired

I suppose the  Form1.DataTimePicker1_OnChange   event should be used.


 procedure Form1.DataTimePicker1_OnChange (Sender: TObject; var Cancel: boolean);
           begin
    // Need this part of code. If date eg 30.12.2020 is expired, do something  (disable Button1, make invisible the TableGrid1 or open  Form2.
end

Form1.DataTimePicker1 is not visible.
Any help?

7 (edited by derek 2020-09-26 16:16:12)

Re: Do something if the preset date has expired

Hi Zlaya,
If you must hard code the date, you could try it something like this (see attached).
Derek.

Post's attachments

Attachment icon presetdate3.zip 335.66 kb, 329 downloads since 2020-09-26 

Re: Do something if the preset date has expired

Thanks, Derek.

Re: Do something if the preset date has expired

What is wrong with this code below?

procedure Form1_OnShow (Sender: TObject; Action: string);
begin
  if formatdatetime('yyyy-mm-dd',now) >= '2020-09-05' then form1.tablegrid1.visible := false;
 form2.show;
end;

begin
end.

Form2 should be visible only when  preset date is expired.

Re: Do something if the preset date has expired

Is this code (based on previous Derek's suggestion, correct?

procedure Form1_OnShow (Sender: TObject; Action: string);
begin
  if formatdatetime('yyyy-mm-dd',now) >= '2020-10-05' then
  begin
  form1.tablegrid1.visible := false;
  form1.button1.enabled := false;
 form2.show;
 end else
  begin
      form1.tablegrid1.visible := true;
      form1.button1.enabled := true;
      form2.Hide
    end;
   end;
begin
end.