2015-11-14 42 views
0

我正在嘗試做一個簡單的登錄表單。當登錄成功時,應該顯示Form2,並且Form1應該隱藏或關閉。但我得到一個編譯器錯誤「缺少操作符或分號」Self.Free後缺少運算符或分號

這裏是我的代碼:

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    if(Key.Text = 'password') then 
    Form2.Show 
    Self.close //Same error with Self.Free or Self.Release 
    else 
    ShowMessage('Failed'); 
    Exit; 
end; 

我在做什麼錯?

回答

5

你缺少一個begin/end塊(你不需要Exit):

procedure TForm1.Button1Click(Sender: TObject); 
begin 
    if (Key.Text = 'password') then 
    begin // <-- add this 
    Form2.Show; 
    Self.Close; 
    end // <-- add this 
    else 
    ShowMessage('Failed'); 
end; 
+0

還缺少兩個分號(了'Show'和'Close'後)。 –

+0

謝謝,但我需要1更多的幫助獲取self.close錯誤時單擊button1,所以我將其更改爲form1.hide但如何關閉form1當我關閉form2 –

+0

你沒有說錯誤是什麼。 'Self.Close;'通常工作得很好,但請注意,默認情況下,關閉'MainForm'將終止程序。所以,假設'TForm1'是你的'MainForm',這種代碼並不特別有用,因爲它目前顯示。 –