Connecting.pas 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. unit Connecting;
  2. interface
  3. uses
  4. Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  5. Dialogs, StdCtrls, ComCtrls, Main, ExtCtrls, WinSock;
  6. type
  7. TfrmConnecting = class(TForm)
  8. pgbTimeOut: TProgressBar;
  9. btnCancel: TButton;
  10. Label1: TLabel;
  11. tmrTimeOut: TTimer;
  12. procedure btnCancelClick(Sender: TObject);
  13. procedure tmrTimeOutTimer(Sender: TObject);
  14. procedure FormShow(Sender: TObject);
  15. private
  16. { Private declarations }
  17. public
  18. { Public declarations }
  19. end;
  20. var
  21. frmConnecting: TfrmConnecting;
  22. implementation
  23. {$R *.dfm}
  24. procedure TfrmConnecting.btnCancelClick(Sender: TObject);
  25. begin
  26. Screen.Cursor := crHourGlass;
  27. tmrTimeOut.Enabled := False;
  28. closesocket(pSock);
  29. closesocket(pRSock);
  30. WSACleanup;
  31. //TerminateThread(ThreadDebugHandle, 0);
  32. Screen.Cursor := crDefault;
  33. end;
  34. procedure TfrmConnecting.tmrTimeOutTimer(Sender: TObject);
  35. begin
  36. Application.ProcessMessages;
  37. Self.Activate;
  38. if pgbTimeOut.Position < pgbTimeOut.Max then
  39. begin
  40. pgbTimeOut.StepBy(1);
  41. end
  42. else
  43. begin
  44. tmrTimeOut.Enabled := False;
  45. Application.MessageBox('The connection timeout has been reached!', 'LuaEdit', MB_OK+MB_ICONERROR);
  46. btnCancel.Click;
  47. end;
  48. {if WaitForSingleObject(hMutex, 30) <> WAIT_TIMEOUT then
  49. begin
  50. // A connection has been made so we close this form and start debugging
  51. ReleaseMutex(hMutex);
  52. tmrTimeOut.Enabled := False;
  53. Self.Close;
  54. end;}
  55. end;
  56. procedure TfrmConnecting.FormShow(Sender: TObject);
  57. begin
  58. tmrTimeOut.Enabled := True;
  59. pgbTimeOut.Position := 0;
  60. end;
  61. end.