首页 > 解决方案 > Why is my Delphi code not executing in order?

问题描述

I am creating a program, and I need to display an image and then block input for a few seconds before allowing it again. The problem I am running into is that Delphi is not running the code in order and is executing the Sleep() command before the image command. I have run into this problem before when using Sleep() with a video before displaying a message.

The code looks as follows:

procedure TtForm.WindowsMediaPlayer2Click(ASender: TObject;
  nButton, nShiftState: SmallInt; fX, fY: Integer);                          
Var                                                                            
  buttonSelected: Integer;                                                  
begin                                                                     
  buttonSelected := MessageDlg('Well done Monkey!-_-', mtError, mbOKCancel, 0);                                                            
  if buttonSelected = mrOK then                                              
  begin            
    Pages.Visible := False;                                                
    WindowsMediaPlayer2.Visible := False;                                      
    imgEroor.BringToFront;                                                  
    BorderStyle := bsNone;                                                   
    WindowState := wsMaximized;                                             
    imgEroor.Top := 0;                                                       
    imgEroor.Left := 0;                                                         
                                                                              
    imgEroor.Width := Screen.Width;                                                 
    imgEroor.Height := Screen.Height;                                       
    imgEroor.BringToFront;                                               
                                                                        
    BlockInput(True);                                             
    Sleep(10000);                                                         
    BlockInput(False);                                                    
  end;
                                                                   
  if buttonSelected = mrCancel then                                                    
  begin                                           
    Pages.Visible := False;                                               
    WindowsMediaPlayer2.Visible := False;                                   
    imgEroor.BringToFront;                                                 
    BorderStyle := bsNone;                                                      
    WindowState := wsMaximized;                                                
    imgEroor.Top := 0;                                                     
    imgEroor.Left := 0;                                                        
                                                                              
    imgEroor.Width := Screen.Width;                                         
    imgEroor.Height := Screen.Height;                                          
    imgEroor.BringToFront;                                                     
                                                                            
    BlockInput(True);                                                   
    Sleep(10000);                                                         
    BlockInput(False);                                                    
  end;                                                                    
end;                                                                          

标签: imagedelphivideosleep

解决方案


推荐阅读