serial: improve nil check

This commit is contained in:
2023-11-19 22:39:32 +08:00
parent b274cbc6f3
commit 348dba5234
3 changed files with 16 additions and 11 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ object MainForm: TMainForm
Height = 580
Top = 10
Width = 940
ActivePage = TabSheet2
ActivePage = SerialTabSheet
Anchors = [akTop, akLeft, akRight, akBottom]
BorderSpacing.Left = 10
BorderSpacing.Top = 10
@@ -34,7 +34,7 @@ object MainForm: TMainForm
Font.Pitch = fpVariable
Font.Quality = fqDraft
ParentFont = False
TabIndex = 1
TabIndex = 0
TabOrder = 0
object SerialTabSheet: TTabSheet
Caption = '串口'
+2 -2
View File
@@ -5,8 +5,8 @@ unit mainunit;
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,
ComCtrls, Spin, MaskEdit, SpinEx, Synaser, SerialManager, Types,
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls,
ComCtrls, MaskEdit, SpinEx, Synaser, SerialManager,
SerialPortFrameUnit, TCPFrameUnit;
type
+12 -7
View File
@@ -69,21 +69,26 @@ end;
procedure SerialThread.Close;
begin
MserialPort.Purge();
MserialPort.CloseSocket();
Terminate();
FreeAndNil(MserialPort);
ProcessOnCloseEvent();
if MserialPort <> nil then
begin
MserialPort.Purge();
MserialPort.CloseSocket();
Terminate();
FreeAndNil(MserialPort);
ProcessOnCloseEvent();
end;
end;
procedure SerialThread.SendString(Data: ansistring);
begin
MserialPort.SendString(Data);
if (MserialPort <> nil) and isConnected() then
MserialPort.SendString(Data);
end;
function SerialThread.SendBuffer(buffer: pointer; length: integer): integer;
begin
Result := MserialPort.SendBuffer(buffer, length);
if (MserialPort <> nil) and isConnected() then
Result := MserialPort.SendBuffer(buffer, length);
end;
procedure SerialThread.ConfigureSerial(baud, bits: integer; parity: char;