You should use handle of some control as parameter of CloseWindow function. procedure TForm1.Button1Click(Sender: TObject); begin CloseWindow(Edit1.Handle); end;