From e2aa3d7e586eafc755f375200f8259f2e65feaf6 Mon Sep 17 00:00:00 2001 From: Jan Horacek Date: Thu, 16 Mar 2017 17:01:03 +0100 Subject: [PATCH] Osetrena vyjimka Connected property. Dotaz na TCPklient.connected muze vyvolat vyjimku pri nasilne prerusenem spojeni. --- src/LokTokens.pas | 7 +------ src/ModelovyCas.pas | 4 ---- src/Sounds.pas | 1 + src/TCPClientPanel.pas | 36 ++++++++++++++++++++++++++++-------- src/hJOPpanel.dproj | 4 ++-- src/uLIclient.pas | 26 +++++++++++++++++++++----- 6 files changed, 53 insertions(+), 25 deletions(-) diff --git a/src/LokTokens.pas b/src/LokTokens.pas index d58fa4b..fa8c00b 100644 --- a/src/LokTokens.pas +++ b/src/LokTokens.pas @@ -153,15 +153,10 @@ procedure TTokens.ResetMausTokens(); //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// - initialization tokens := TTokens.Create(); finalization FreeAndNil(tokens); + end. diff --git a/src/ModelovyCas.pas b/src/ModelovyCas.pas index c514dcf..00ada42 100644 --- a/src/ModelovyCas.pas +++ b/src/ModelovyCas.pas @@ -128,10 +128,6 @@ procedure TModCas.Reset(); //////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////////////// - initialization ModCas := TModCas.Create(); diff --git a/src/Sounds.pas b/src/Sounds.pas index f117b5c..79715f6 100644 --- a/src/Sounds.pas +++ b/src/Sounds.pas @@ -224,4 +224,5 @@ initialization SoundsPlay := TSoundsPlay.Create(); finalization FreeAndNil(SoundsPlay); + end.//unit diff --git a/src/TCPClientPanel.pas b/src/TCPClientPanel.pas index 850bc50..100ede3 100644 --- a/src/TCPClientPanel.pas +++ b/src/TCPClientPanel.pas @@ -335,8 +335,12 @@ constructor TPanelTCPClient.Create(); destructor TPanelTCPClient.Destroy(); begin - if (Self.tcpClient.Connected) then - Self.tcpClient.Disconnect(); + try + if (Self.tcpClient.Connected) then + Self.tcpClient.Disconnect(); + except + + end; // Znicime resuscitacni vlakno (vlakno obnovujici spojeni). if (Assigned(Self.resusct)) then @@ -352,11 +356,19 @@ destructor TPanelTCPClient.Destroy(); end; end; - if (Assigned(Self.tcpClient)) then - FreeAndNil(Self.tcpClient); + try + if (Assigned(Self.tcpClient)) then + FreeAndNil(Self.tcpClient); + except + + end; - if (Assigned(Self.parsed)) then - FreeAndNil(Self.parsed); + try + if (Assigned(Self.parsed)) then + FreeAndNil(Self.parsed); + except + + end; inherited Destroy(); end;//dtor @@ -400,7 +412,11 @@ function TPanelTCPClient.Connect(host:string; port:Word):Integer; function TPanelTCPClient.Disconnect():Integer; begin - if (not Self.tcpClient.Connected) then Exit(1); + try + if (not Self.tcpClient.Connected) then Exit(1); + except + + end; Self.control_disconnect := true; if Assigned(Self.rthread) then Self.rthread.Terminate; @@ -999,7 +1015,11 @@ function TPanelTCPClient.StrToColor(str:string):TColor; procedure TPanelTCPClient.SendLn(str:string); begin - if (not Self.tcpClient.Connected) then Exit; + try + if (not Self.tcpClient.Connected) then Exit; + except + + end; try Self.tcpClient.Socket.WriteLn(str); diff --git a/src/hJOPpanel.dproj b/src/hJOPpanel.dproj index afe635d..9572bfe 100644 --- a/src/hJOPpanel.dproj +++ b/src/hJOPpanel.dproj @@ -166,7 +166,7 @@ True 1 4 - 5 + 6 0 False False @@ -179,7 +179,7 @@ Panel stanice hJOP - 1.4.5.0 + 1.4.6.0 hJOPpanel.exe Jan Horáček Jan Horáček diff --git a/src/uLIclient.pas b/src/uLIclient.pas index d595f11..2fb159f 100644 --- a/src/uLIclient.pas +++ b/src/uLIclient.pas @@ -142,8 +142,12 @@ constructor TBridgeClient.Create(); destructor TBridgeClient.Destroy(); begin - if (Self.tcpClient.Connected) then - Self.tcpClient.Disconnect(); + try + if (Self.tcpClient.Connected) then + Self.tcpClient.Disconnect(); + except + + end; Self.DestroyResusc(); @@ -189,7 +193,11 @@ function TBridgeClient.Connect(host:string; port:Word):Integer; function TBridgeClient.Disconnect():Integer; begin - if (not Self.tcpClient.Connected) then Exit(1); + try + if (not Self.tcpClient.Connected) then Exit(1); + except + + end; Self.control_disconnect := true; if Assigned(Self.rthread) then Self.rthread.Terminate; @@ -326,7 +334,11 @@ procedure TBridgeClient.Parse(); procedure TBridgeClient.SendLn(str:string); begin - if (not Self.tcpClient.Connected) then Exit; + try + if (not Self.tcpClient.Connected) then Exit; + except + + end; try Self.tcpClient.Socket.WriteLn(str); @@ -339,7 +351,11 @@ procedure TBridgeClient.SendLn(str:string); function TBridgeClient.GetOpened():boolean; begin - Result := Self.tcpClient.Connected; + try + Result := Self.tcpClient.Connected; + except + Result := false; + end; end; ////////////////////////////////////////////////////////////////////////////////