2017-02-25 110 views
0

似乎無法找到這個在這裏的答案。最有可能非常簡單,但因爲我只是一個德爾菲「Dabbler」我一直無法弄清楚。 我有一個初始屏幕,當然它會首先啓動,但它也可以作爲登錄屏幕。用戶輸入他們的名字,他們可以訪問。但是,如果在15分鐘內沒有任何輸入,我希望應用程序以默認用戶名登錄,並告訴我沒有實際用戶登錄。大部分內容都覆蓋了,只是無法計算了解如何讓它超時。我認爲它必須在類功能somwhere但.....這裏是代碼。先謝謝你們。如何獲取飛濺窗體在德爾福超時

class function TSplashForm.Execute: boolean; 
begin 
    with TSplashForm.Create(nil) do 
    try 
    Result := ShowModal = mrOk; 
    finally 
    Free; 
end; 
end; 

procedure TSplashForm.btnOKClick(Sender: TObject); 
begin 
    if edtLoginname.Text = UName then 
    ModalResult := mrOK 
    else 
    begin 
    ModalResult := mrNone; 
    ShowMessage(edtLoginName.Text+' is an Incorrect Username.....Try AGAIN'); 
    edtLoginName.Text := ''; 
    end; 
end; 
+0

運行的定時器。如果過期,請關閉表單。 –

+0

大衛。我認爲定時器將是答案,但我在哪裏放置代碼,在類函數我相信但我使用REPEAT UNTIL語句或{If(result = mrOK)或(MyTimer = xxxxx)然後}默認登錄。 ...... –

+0

真的沒關係。計時器可以在任何地方。當它到期時關閉表單。 –

回答

1

簡單地講了TTimer飛濺形式,將其Interval至15分鐘,並有其OnTimer事件關閉窗體。用戶每輸入一次,重置計時器。

procedure TSplashForm.edtLoginnameChange(Sender: TObject); 
begin 
    Timer1.Enabled := false; 
    Timer1.Enabled:= true; 
end; 

procedure TSplashForm.Timer1Timer(Sender: TObject); 
begin 
    ModalResult := mrIgnore; 
end; 

procedure TSplashForm.btnOKClick(Sender: TObject); 
begin 
    if edtLoginname.Text = UName then 
    ModalResult := mrOK 
    else begin 
    ModalResult := mrNone; 
    ShowMessage(edtLoginName.Text+' is an Incorrect Username.....Try AGAIN'); 
    edtLoginName.Clear; 
    end; 
end; 

然後,你可以這樣做:

class function TSplashForm.Execute: Integer; 
begin 
    with TSplashForm.Create(nil) do 
    try 
    Result := ShowModal; 
    finally 
    Free; 
    end; 
end; 

case TSplashForm.Execute of 
    mrOK: // user logged in... 
    mrIgnore: // timed out... 
else 
    // cancelled ... 
end;