Dismiss Notice

REGISTRATION IS AFTER ADMIN ACTIVATION

DONATIONS WITH PAYPAL CLICK TO BUTTON

3 MONTHS VIP - 10$; 6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$

DONATIONS WITH Bitcoin Address:3NRs3CK3fhXifrNYxHEZKpETDd9vNLMsMD

Dismiss Notice
The registration is approved by the Administrator. It takes about 1 day to approve your registration
Dismiss Notice
For open hidden message no need write thanks, thank etc. Enough is click to like button on right side of thread.

TTimer cancel operation if 'busy'

Discussion in 'Delphi Programming' started by aikona, Feb 12, 2014.

  1. aikona
    Offline

    aikona DF Member

    Hi

    I am using a timer to check for time based changes ( example : at midnight , date in datetimepicker has to update to new date

    So I use a 60s ttimer : but I also want to give the user the option of not chhanging the date ( yet) .I bring up a  MessageDlg asking the user to accept new date or cancel ...

    Now the problem : Message comes up but user went for coffe and does not reponds for say twenty minutes....User comes back accepts or cancel AND .... He now has to accept or cancel all the other timer message that are queeued up .How can I ignore the followup ttimer events ?

    Eric
     
  2. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    RE:

    can you share code or project?
     
  3. aikona
    Offline

    aikona DF Member

    We'll try

    I have a TTimer object on form set to 60000 ( or 60 seconds)

    Here is the OnTimer event

    procedure TMain1.Timer1Timer(Sender: TObject);
    begin
    // Use for changing date and shift
    // For updating date and time
    // For saving stuff to database
    // Fires every minute
    // If new day then change date
    // if new shift then message and get ready to change shift
    // REM is 'a test' code
    if Datetostr(Datetime1.Date) < Datetostr(Date)  then
    Begin if (MessageDlg('Do you want to accept the new date', mtWarning, [mbOK, mbCancel], 0) in [mrOk]) then
    Begin
    Datetime1.Date := Date ;
    end

          else
     // Ok lets save the stuff.
        end ;


    If nobody responds to the message then after 5 minutes you will have 5 queued messages meaning you will have to press the button five times .

    I suppose I could look if a MessageDlg has focus
    OR
    Set a bit in the beginning of the event and resetting at the end and check if bit Hi or low  but that ssems very crude programming

     Maybe somebody knows a better way ( read more elegant way)

    [hr]
    Oh yes just an tip

    if Datetime1.Date < Date  then : DOES NOT WORK
    if Datetostr(Datetime1.Date) < Datetostr(Date)  then : WORKS 

    Datetime1 is datetimepicker component
    Date is ... date from the DateUtils
    Anybody can with an explanation
     
  4. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    RE:

    for example :
    your datetimepicker date = 11.02.2014
    and date is 12.02.2014 
    you say if you dont press button ok after 5 minutes you must press button 5 times ,OK?

    You need just one message?
    if this is right you make basicly like this:

    Code:
    procedure TMain1.Timer1Timer(Sender: TObject);
    
    begin
    // Use for changing date and shift
    // For updating date and time
    // For saving stuff to database
    // Fires every minute
    // If new day then change date
    // if new shift then message and get ready to change shift
    // REM is 'a test' code
    if Datetostr(Datetime1.Date) < Datetostr(Date)  then
    Begin 
    timer1.enabled:=false;
    if (MessageDlg('Do you want to accept the new date', mtWarning, [mbOK, mbCancel], 0) in [mrOk]) then
    Begin
    Datetime1.Date := Date ;
    timer1.enabled:=true;
    end
    
          else
     // Ok lets save the stuff.
        end ;
    
     
  5. N0body
    Online

    N0bodyN0body is a Verified Member DelphiFan Administrator Staff Member DF Staff

    RE:

    after this your message show just one time after press ok timer is enable true
     
  6. aikona
    Offline

    aikona DF Member

    Thank you ... this is what I call 'elegant programming' ( or keep it simple)
    Eric
     
  7. LipsofAshes
    Offline

    LipsofAshes DF Member

    RE:

    Create a Global boolean var lets say bExecuteTimer

    at form create or show make bExecuteTimer := False;

    at timer in 1 line put if bExecuteTimer then exit; 
    this will exit the timer event if the tier is already running

    after that line do bExecuteTimer := True; //will make the var true so next time timmer executes it will exit until  this one is done 
    try
    run all your code here
    finally 
    bExecuteTimer := False; // setting it again to false will allow the next time the timer executes to do all the code
    end;
     

Share This Page

Laws
Our website, law, laws, copyright and aims to be respectful of individual rights. Our site, as defined in the law of 5651 serves as a provider of space. According to the law, contrary to the law of site management has no obligation to monitor content. Therefore, our site has adopted the principle of fit and remove. Works are subject to copyright laws and is shared in a manner that violated their legal rights, or professional associations, rights holders who, adsdelphi@gmail.com I can reach us at e-mail address. Complaints considered to be infringing on the examination of the content will be removed from our site.
Donate Help To Us and Be VIP
DONATIONS WITH PAYPAL CLICK TO BUTTON
6 MONTHS VIP - 20$; 1 YEAR VIP - 30$; 2 YEARS VIP - 50$; GOLD USER FOR LIFE VIP - 150$
Social Block