CnRS232Dialog.pas 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. {******************************************************************************}
  2. { CnPack For Delphi/C++Builder }
  3. { 中国人自己的开放源码第三方开发包 }
  4. { (C)Copyright 2001-2018 CnPack 开发组 }
  5. { ------------------------------------ }
  6. { }
  7. { 本开发包是开源的自由软件,您可以遵照 CnPack 的发布协议来修 }
  8. { 改和重新发布这一程序。 }
  9. { }
  10. { 发布这一开发包的目的是希望它有用,但没有任何担保。甚至没有 }
  11. { 适合特定目的而隐含的担保。更详细的情况请参阅 CnPack 发布协议。 }
  12. { }
  13. { 您应该已经和开发包一起收到一份 CnPack 发布协议的副本。如果 }
  14. { 还没有,可访问我们的网站: }
  15. { }
  16. { 网站地址:http://www.cnpack.org }
  17. { 电子邮件:master@cnpack.org }
  18. { }
  19. {******************************************************************************}
  20. unit CnRS232Dialog;
  21. {* |<PRE>
  22. ================================================================================
  23. * 软件名称:网络通讯组件包
  24. * 单元名称:CnRS232Dialog 串口设置对话框组件及窗体单元
  25. * 单元作者:周劲羽 (zjy@cnpack.org)
  26. * 备 注:
  27. * 开发平台:PWin98SE + Delphi 5.0
  28. * 兼容测试:PWin9X/2000/XP + Delphi 5/6
  29. * 本 地 化:该单元代码中的字符串符合本地化处理方式
  30. * 该单元窗体中的字符串还不符合本地化处理方式
  31. * 单元标识:$Id$
  32. * 修改记录:2002.04.18 V1.1
  33. * 重申明CommConfig和Timeouts为发布属性
  34. * 2002.04.08 V1.0
  35. * 创建单元
  36. * 增加注释
  37. ================================================================================
  38. |</PRE>}
  39. interface
  40. {$I CnPack.inc}
  41. uses
  42. Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  43. ComCtrls, StdCtrls, Buttons, CnClasses, CnConsts, CnRS232, CnNetConsts,
  44. CnSpin;
  45. type
  46. //------------------------------------------------------------------------------
  47. // 串口设置对话框窗体
  48. //------------------------------------------------------------------------------
  49. { TCnRS232Dlg }
  50. TCnRS232Dlg = class(TForm)
  51. pcCommConfig: TPageControl;
  52. tsNormal: TTabSheet;
  53. tsXonXoff: TTabSheet;
  54. bbtnOk: TBitBtn;
  55. bbtnCancel: TBitBtn;
  56. cbbBaudRate: TComboBox;
  57. lblBaudRate: TLabel;
  58. cbTxContinueOnXoff: TCheckBox;
  59. cbOutx_XonXoffFlow: TCheckBox;
  60. cbInx_XonXoffFlow: TCheckBox;
  61. lblByteSize: TLabel;
  62. cbbByteSize: TComboBox;
  63. lblParity: TLabel;
  64. cbbParity: TComboBox;
  65. lblStopBits: TLabel;
  66. cbbStopBits: TComboBox;
  67. lblXonLimit: TLabel;
  68. lblXoffLimit: TLabel;
  69. lblXonChar: TLabel;
  70. lblXoffChar: TLabel;
  71. tsHardware: TTabSheet;
  72. lblDtrControl: TLabel;
  73. lblRtsControl: TLabel;
  74. cbOutx_CtsFlow: TCheckBox;
  75. cbOutx_DsrFlow: TCheckBox;
  76. cbDsrSensitivity: TCheckBox;
  77. cbbDtrControl: TComboBox;
  78. cbbRtsControl: TComboBox;
  79. cbReplaceWhenParityError: TCheckBox;
  80. cbIgnoreNullChar: TCheckBox;
  81. lblInCtrl: TLabel;
  82. lblOutCtrl: TLabel;
  83. tsTimeouts: TTabSheet;
  84. lblReadIntervalTimeout: TLabel;
  85. lblReadTotalTimeoutMultiplier: TLabel;
  86. lblMSec1: TLabel;
  87. lblMSec2: TLabel;
  88. lblReadTotalTimeoutConstant: TLabel;
  89. lblMSec3: TLabel;
  90. lblWriteTotalTimeoutMultiplier: TLabel;
  91. lblMSec4: TLabel;
  92. lblWriteTotalTimeoutConstant: TLabel;
  93. lblMSec5: TLabel;
  94. cbShowHint: TCheckBox;
  95. seReplacedChar: TCnSpinEdit;
  96. seXonLimit: TCnSpinEdit;
  97. seXonChar: TCnSpinEdit;
  98. seXoffChar: TCnSpinEdit;
  99. seXoffLimit: TCnSpinEdit;
  100. seReadIntervalTimeout: TCnSpinEdit;
  101. seReadTotalTimeoutMultiplier: TCnSpinEdit;
  102. seReadTotalTimeoutConstant: TCnSpinEdit;
  103. seWriteTotalTimeoutMultiplier: TCnSpinEdit;
  104. seWriteTotalTimeoutConstant: TCnSpinEdit;
  105. procedure FormCreate(Sender: TObject);
  106. procedure FormDestroy(Sender: TObject);
  107. procedure cbbBaudRateExit(Sender: TObject);
  108. procedure bbtnOkClick(Sender: TObject);
  109. procedure seReplacedCharExit(Sender: TObject);
  110. procedure FormShow(Sender: TObject);
  111. procedure seXonLimitExit(Sender: TObject);
  112. procedure ControlChanged(Sender: TObject);
  113. procedure cbShowHintClick(Sender: TObject);
  114. private
  115. { Private declarations }
  116. FCommConfig: TCnRS232Config;
  117. FTimeouts: TCnRS232Timeouts;
  118. procedure SetCommConfig(const Value: TCnRS232Config);
  119. procedure SetCommTimeouts(const Value: TCnRS232Timeouts);
  120. procedure ReadCommConfig;
  121. procedure WriteCommConfig;
  122. procedure ReadCommTimeouts;
  123. procedure WriteCommTimeouts;
  124. public
  125. { Public declarations }
  126. property CommConfig: TCnRS232Config read FCommConfig write SetCommConfig;
  127. property CommTimeouts: TCnRS232Timeouts read FTimeouts write SetCommTimeouts;
  128. end;
  129. //------------------------------------------------------------------------------
  130. // 串口设置对话框组件
  131. //------------------------------------------------------------------------------
  132. { TCnRS232Dialog }
  133. TCnRS232DialogKind = (ckWin32, ckExtended);
  134. {* 串口设置对话框风格
  135. |<PRE>
  136. ckWin32: - Win32标准风格
  137. ckExtended: - 扩展对话框风格
  138. |</PRE>}
  139. TCnRS232DialogPages = set of (cpNormal, cpXonXoff, cpHardware, cpTimeouts);
  140. {* 串口设置对话框显示页面集合
  141. |<PRE>
  142. cpNormal: - 常规设置页面
  143. cpXonXoff: - 软件流量控制页面
  144. cpHardware: - 硬件流量控制页面
  145. cpTimeouts: - 超时设置页面
  146. |</PRE>}
  147. TCnRS232DialogShowHint = (csHint, csNoHint, csCheckHint, csCheckNoHint);
  148. {* 串口设置对话框工具提示信息显示方式
  149. |<PRE>
  150. csHint: - 显示工具提示
  151. csNoHint: - 不显示工具提示
  152. csCheckHint: - 由单选框决定,默认为显示
  153. csCheckNoHint: - 由单选框决定,默认为不显示
  154. |</PRE>}
  155. TCnRS232Dialog = class(TCnComponent)
  156. {* RS232串口设置对话框组件。
  157. |<PRE>
  158. * 组件用于显示串口设置对话框,一般搭配TCnRS232组件使用。
  159. * 使用方式类似于VCL中的常规对话框组件。
  160. |</PRE>}
  161. private
  162. FCommConfig: TCnRS232Config;
  163. FTimeouts: TCnRS232Timeouts;
  164. FKind: TCnRS232DialogKind;
  165. FPages: TCnRS232DialogPages;
  166. FCommName: string;
  167. FTitle: string;
  168. FBaudRateList: Boolean;
  169. FShowHint: TCnRS232DialogShowHint;
  170. FOnClose: TNotifyEvent;
  171. FOnShow: TNotifyEvent;
  172. procedure SetCommConfig(const Value: TCnRS232Config);
  173. procedure SetTimeouts(const Value: TCnRS232Timeouts);
  174. function GetHandle: THandle;
  175. protected
  176. procedure GetComponentInfo(var AName, Author, Email, Comment: string); override;
  177. procedure AssignTo(Dest: TPersistent); override;
  178. procedure DoShow; virtual;
  179. procedure DoClose; virtual;
  180. public
  181. procedure Assign(Source: TPersistent); override;
  182. {* 对象赋值方法,允许从TCnRS232中赋值}
  183. constructor Create(AOwner: TComponent); override;
  184. destructor Destroy; override;
  185. function Execute: Boolean;
  186. {* 显示对话框,如果用户点击了“确认”按钮,返回为真}
  187. property CommName: string read FCommName write FCommName;
  188. {* 串口端口名}
  189. published
  190. property Title: string read FTitle write FTitle;
  191. {* 对话框标题,仅当 Kind 属性为 ckExtended 扩展风格时有效}
  192. property Kind: TCnRS232DialogKind read FKind write FKind default ckExtended;
  193. {* 对话框风格}
  194. property Pages: TCnRS232DialogPages read FPages write FPages default
  195. [cpNormal, cpXonXoff, cpHardware];
  196. {* 对话框可显示的页面集合,仅当 Kind 属性为 ckExtended 扩展风格时有效}
  197. property BaudRateList: Boolean read FBaudRateList write FBaudRateList default True;
  198. {* 对话框中的波特率参数是否只允许从下拉列表中选择。如果为假,用户可自定义
  199. 非标准的小特率。仅当 Kind 属性为 ckExtended 扩展风格时有效}
  200. property ShowHint: TCnRS232DialogShowHint read FShowHint write FShowHint default
  201. csNoHint;
  202. {* 显示对话框中工具提示的方式,仅当 Kind 属性为 ckExtended 扩展风格时有效}
  203. property CommConfig: TCnRS232Config read FCommConfig write SetCommConfig;
  204. {* 串口通讯设置}
  205. property Timeouts: TCnRS232Timeouts read FTimeouts write SetTimeouts;
  206. {* 串口通讯超时设置}
  207. property OnClose: TNotifyEvent read FOnClose write FOnClose;
  208. {* 对话框关闭事件}
  209. property OnShow: TNotifyEvent read FOnShow write FOnShow;
  210. {* 对话框显示事件}
  211. end;
  212. implementation
  213. {$R *.DFM}
  214. //------------------------------------------------------------------------------
  215. // 串口设置对话框窗体
  216. //------------------------------------------------------------------------------
  217. { TCnRS232Dlg }
  218. // 窗体创建
  219. procedure TCnRS232Dlg.FormCreate(Sender: TObject);
  220. begin
  221. FCommConfig := TCnRS232Config.Create;
  222. FTimeouts := TCnRS232Timeouts.Create;
  223. WriteCommConfig;
  224. WriteCommTimeouts;
  225. end;
  226. // 窗体释放
  227. procedure TCnRS232Dlg.FormDestroy(Sender: TObject);
  228. begin
  229. FCommConfig.Free;
  230. FTimeouts.Free;
  231. end;
  232. // 窗体显示
  233. procedure TCnRS232Dlg.FormShow(Sender: TObject);
  234. begin
  235. WriteCommConfig;
  236. WriteCommTimeouts;
  237. ControlChanged(Self);
  238. end;
  239. // 确定
  240. procedure TCnRS232Dlg.bbtnOkClick(Sender: TObject);
  241. begin
  242. ReadCommConfig;
  243. ReadCommTimeouts;
  244. ModalResult := mrOK;
  245. end;
  246. // 从控件中取串口设置
  247. procedure TCnRS232Dlg.ReadCommConfig;
  248. begin
  249. with FCommConfig do
  250. begin
  251. XoffChar := Char(seXoffChar.Value);
  252. ReplacedChar := Char(seReplacedChar.Value);
  253. XonChar := Char(seXonChar.Value);
  254. Outx_CtsFlow := cbOutx_CtsFlow.Checked;
  255. Outx_DsrFlow := cbOutx_DsrFlow.Checked;
  256. ParityCheck := cbbParity.ItemIndex <> 0;
  257. IgnoreNullChar := cbIgnoreNullChar.Checked;
  258. Inx_XonXoffFlow := cbInx_XonXoffFlow.Checked;
  259. TxContinueOnXoff := cbTxContinueOnXoff.Checked;
  260. ReplaceWhenParityError := cbReplaceWhenParityError.Checked;
  261. Outx_XonXoffFlow := cbOutx_XonXoffFlow.Checked;
  262. DsrSensitivity := cbDsrSensitivity.Checked;
  263. BaudRate := StrToInt(cbbBaudRate.Text);
  264. ByteSize := TByteSize(cbbByteSize.ItemIndex);
  265. DtrControl := TDtrControl(cbbDtrControl.ItemIndex);
  266. Parity := TParity(cbbParity.ItemIndex);
  267. RtsControl := TRtsControl(cbbRtsControl.ItemIndex);
  268. StopBits := TStopBits(cbbStopBits.ItemIndex);
  269. XoffLimit := seXoffLimit.Value;
  270. XonLimit := seXonLimit.Value;
  271. end;
  272. end;
  273. // 从控件中取超时设置
  274. procedure TCnRS232Dlg.ReadCommTimeouts;
  275. begin
  276. with FTimeouts do
  277. begin
  278. ReadTotalTimeoutConstant := seReadTotalTimeoutConstant.Value;
  279. ReadIntervalTimeout := seReadIntervalTimeout.Value;
  280. ReadTotalTimeoutMultiplier := seReadTotalTimeoutMultiplier.Value;
  281. WriteTotalTimeoutConstant := seWriteTotalTimeoutConstant.Value;
  282. WriteTotalTimeoutMultiplier := seWriteTotalTimeoutMultiplier.Value;
  283. end;
  284. end;
  285. // 根据参数设置控件
  286. procedure TCnRS232Dlg.WriteCommConfig;
  287. begin
  288. with FCommConfig do
  289. begin
  290. seXoffChar.Value := Byte(XoffChar);
  291. seReplacedChar.Value := Byte(ReplacedChar);
  292. seXonChar.Value := Byte(XonChar);
  293. cbOutx_CtsFlow.Checked := Outx_CtsFlow;
  294. cbOutx_DsrFlow.Checked := Outx_DsrFlow;
  295. cbIgnoreNullChar.Checked := IgnoreNullChar;
  296. cbInx_XonXoffFlow.Checked := Inx_XonXoffFlow;
  297. cbTxContinueOnXoff.Checked := TxContinueOnXoff;
  298. cbReplaceWhenParityError.Checked := ReplaceWhenParityError;
  299. cbOutx_XonXoffFlow.Checked := Outx_XonXoffFlow;
  300. cbDsrSensitivity.Checked := DsrSensitivity;
  301. if cbbBaudRate.Style = csDropDown then
  302. cbbBaudRate.Text := IntToStr(BaudRate)
  303. else
  304. begin
  305. cbbBaudRate.ItemIndex := cbbBaudRate.Items.IndexOf(IntToStr(BaudRate));
  306. if cbbBaudRate.ItemIndex < 0 then
  307. cbbBaudRate.ItemIndex := cbbBaudRate.Items.Add(IntToStr(BaudRate));
  308. end;
  309. cbbByteSize.ItemIndex := Ord(ByteSize);
  310. cbbDtrControl.ItemIndex := Ord(DtrControl);
  311. cbbParity.ItemIndex := Ord(Parity);
  312. cbbRtsControl.ItemIndex := Ord(RtsControl);
  313. cbbStopBits.ItemIndex := Ord(StopBits);
  314. seXoffLimit.Value := XoffLimit;
  315. seXonLimit.Value := XonLimit;
  316. end;
  317. end;
  318. // 根据超时参数设置控件
  319. procedure TCnRS232Dlg.WriteCommTimeouts;
  320. begin
  321. with FTimeouts do
  322. begin
  323. seReadTotalTimeoutConstant.Value := ReadTotalTimeoutConstant;
  324. seReadIntervalTimeout.Value := ReadIntervalTimeout;
  325. seReadTotalTimeoutMultiplier.Value := ReadTotalTimeoutMultiplier;
  326. seWriteTotalTimeoutConstant.Value := WriteTotalTimeoutConstant;
  327. seWriteTotalTimeoutMultiplier.Value := WriteTotalTimeoutMultiplier;
  328. end;
  329. end;
  330. // 设置参数
  331. procedure TCnRS232Dlg.SetCommConfig(const Value: TCnRS232Config);
  332. begin
  333. FCommConfig.Assign(Value);
  334. WriteCommConfig;
  335. end;
  336. // 设置超时
  337. procedure TCnRS232Dlg.SetCommTimeouts(const Value: TCnRS232Timeouts);
  338. begin
  339. FTimeouts.Assign(Value);
  340. WriteCommTimeouts;
  341. end;
  342. // 约束波特率
  343. procedure TCnRS232Dlg.cbbBaudRateExit(Sender: TObject);
  344. begin
  345. try
  346. StrToInt(cbbBaudRate.Text);
  347. except
  348. MessageBox(Handle, PChar(SBaudRateError), PChar(SCnError), MB_OK + MB_ICONSTOP);
  349. cbbBaudRate.SetFocus;
  350. end;
  351. end;
  352. // 约束字符编辑控件
  353. procedure TCnRS232Dlg.seReplacedCharExit(Sender: TObject);
  354. var
  355. i: Integer;
  356. begin
  357. if Sender is TCnSpinEdit then
  358. try
  359. i := StrToInt(TCnSpinEdit(Sender).Text);
  360. if (i > 255) or (i < 0) then
  361. raise Exception.Create(SCnError);
  362. if seXonChar.Text = seXoffChar.Text then
  363. begin
  364. MessageBox(Handle, PChar(SInvalidXonXoffChar), PChar(SCnError),
  365. MB_OK + MB_ICONSTOP);
  366. TCnSpinEdit(Sender).SetFocus;
  367. end;
  368. except
  369. MessageBox(Handle, PChar(SInputASCIICode), PChar(SCnError), MB_OK + MB_ICONSTOP);
  370. TCnSpinEdit(Sender).SetFocus;
  371. end;
  372. end;
  373. // 约束整数编辑控件
  374. procedure TCnRS232Dlg.seXonLimitExit(Sender: TObject);
  375. var
  376. i: Integer;
  377. begin
  378. if Sender is TCnSpinEdit then
  379. try
  380. i := StrToInt(TCnSpinEdit(Sender).Text);
  381. if (i > MaxWord) or (i < 0) then
  382. raise Exception.Create(SCnError);
  383. except
  384. MessageBox(Handle, PChar(SInputInteger), PChar(SCnError), MB_OK + MB_ICONSTOP);
  385. TCnSpinEdit(Sender).SetFocus;
  386. end;
  387. end;
  388. // 设置控件状态
  389. procedure TCnRS232Dlg.ControlChanged(Sender: TObject);
  390. begin
  391. cbReplaceWhenParityError.Enabled := cbbParity.ItemIndex > 0;
  392. seReplacedChar.Enabled := cbReplaceWhenParityError.Enabled and
  393. cbReplaceWhenParityError.Checked;
  394. end;
  395. // 设置工具提示
  396. procedure TCnRS232Dlg.cbShowHintClick(Sender: TObject);
  397. begin
  398. ShowHint := cbShowHint.Checked;
  399. end;
  400. //------------------------------------------------------------------------------
  401. // 串口设置对话框组件
  402. //------------------------------------------------------------------------------
  403. { TCnRS232Dialog }
  404. // 对象赋值方法
  405. procedure TCnRS232Dialog.Assign(Source: TPersistent);
  406. begin
  407. if Source is TCnRS232 then
  408. begin
  409. FCommConfig.Assign(TCnRS232(Source).CommConfig);
  410. FTimeouts.Assign(TCnRS232(Source).Timeouts);
  411. FCommName := TCnRS232(Source).CommName;
  412. end
  413. else if Source is TCnRS232Dialog then
  414. begin
  415. TCnRS232Dialog(Source).AssignTo(Self);
  416. end
  417. else
  418. inherited;
  419. end;
  420. // 目标对象赋值方法
  421. procedure TCnRS232Dialog.AssignTo(Dest: TPersistent);
  422. begin
  423. if Dest is TCnRS232 then
  424. begin
  425. TCnRS232(Dest).CommConfig := FCommConfig;
  426. TCnRS232(Dest).Timeouts := FTimeouts;
  427. end
  428. else if Dest is TCnRS232Dialog then
  429. begin
  430. TCnRS232Dialog(Dest).FCommConfig.Assign(FCommConfig);
  431. TCnRS232Dialog(Dest).FTimeouts.Assign(FTimeouts);
  432. TCnRS232Dialog(Dest).FCommName := FCommName;
  433. end
  434. else
  435. inherited;
  436. end;
  437. // 初始化
  438. constructor TCnRS232Dialog.Create(AOwner: TComponent);
  439. begin
  440. inherited;
  441. FCommConfig := TCnRS232Config.Create;
  442. FTimeouts := TCnRS232Timeouts.Create;
  443. FKind := ckExtended;
  444. FPages := [cpNormal, cpXonXoff, cpHardware];
  445. FBaudRateList := True;
  446. FShowHint := csNoHint;
  447. end;
  448. // 释放
  449. destructor TCnRS232Dialog.Destroy;
  450. begin
  451. FCommConfig.Free;
  452. FTimeouts.Free;
  453. inherited;
  454. end;
  455. // 对话框关闭
  456. procedure TCnRS232Dialog.DoClose;
  457. begin
  458. if Assigned(FOnClose) then
  459. FOnClose(Self);
  460. end;
  461. // 对话框显示
  462. procedure TCnRS232Dialog.DoShow;
  463. begin
  464. if Assigned(FOnShow) then
  465. FOnShow(Self);
  466. end;
  467. // 显示对话框
  468. function TCnRS232Dialog.Execute: Boolean;
  469. var
  470. CnRS232Dlg: TCnRS232Dlg;
  471. lpCC: TCommConfig;
  472. begin
  473. if FKind = ckExtended then // 扩展风格
  474. begin
  475. CnRS232Dlg := TCnRS232Dlg.Create(Owner);
  476. try
  477. CnRS232Dlg.FCommConfig.Assign(FCommConfig);
  478. CnRS232Dlg.FTimeouts.Assign(FTimeouts);
  479. if FTitle <> '' then
  480. CnRS232Dlg.Caption := FTitle
  481. else if FCommName <> '' then
  482. CnRS232Dlg.Caption := Format('%s (%s)', [CnRS232Dlg.Caption, FCommName]);
  483. if FBaudRateList then
  484. CnRS232Dlg.cbbBaudRate.Style := csDropDownList
  485. else
  486. CnRS232Dlg.cbbBaudRate.Style := csDropDown;
  487. CnRS232Dlg.cbShowHint.Visible := FShowHint in [csCheckHint, csCheckNoHint];
  488. CnRS232Dlg.cbShowHint.Checked := FShowHint in [csHint, csCheckHint];
  489. CnRS232Dlg.ShowHint := CnRS232Dlg.cbShowHint.Checked;
  490. CnRS232Dlg.tsNormal.TabVisible := cpNormal in FPages;
  491. CnRS232Dlg.tsXonXoff.TabVisible := cpXonXoff in FPages;
  492. CnRS232Dlg.tsHardware.TabVisible := cpHardware in FPages;
  493. CnRS232Dlg.tsTimeouts.TabVisible := cpTimeouts in FPages;
  494. if FPages = [] then
  495. CnRS232Dlg.tsNormal.TabVisible := True;
  496. DoShow;
  497. Result := CnRS232Dlg.ShowModal = mrOK;
  498. if Result then
  499. begin
  500. FCommConfig.Assign(CnRS232Dlg.FCommConfig);
  501. FTimeouts.Assign(CnRS232Dlg.FTimeouts);
  502. end;
  503. DoClose;
  504. finally
  505. CnRS232Dlg.Free;
  506. end;
  507. end
  508. else
  509. begin
  510. FillChar(lpCC, SizeOf(lpCC), 0);
  511. lpCC.dwSize := SizeOf(lpCC);
  512. FCommConfig.GetDCB(lpCC.DCB);
  513. DoShow;
  514. Result := CommConfigDialog(PChar(FCommName), GetHandle, lpCC);
  515. if Result then
  516. FCommConfig.SetDCB(lpCC.DCB);
  517. DoClose;
  518. end;
  519. end;
  520. procedure TCnRS232Dialog.GetComponentInfo(var AName, Author, Email, Comment: string);
  521. begin
  522. AName := SCnRS232DialogName;
  523. Author := SCnPack_Zjy;
  524. Email := SCnPack_ZjyEmail;
  525. Comment := SCnRS232DialogComment;
  526. end;
  527. // 取父窗体句柄
  528. function TCnRS232Dialog.GetHandle: THandle;
  529. begin
  530. if Owner is TForm then
  531. Result := TForm(Owner).Handle
  532. else
  533. Result := 0;
  534. end;
  535. // 设置参数
  536. procedure TCnRS232Dialog.SetCommConfig(const Value: TCnRS232Config);
  537. begin
  538. FCommConfig.Assign(Value);
  539. end;
  540. // 设置超时
  541. procedure TCnRS232Dialog.SetTimeouts(const Value: TCnRS232Timeouts);
  542. begin
  543. FTimeouts.Assign(Value);
  544. end;
  545. end.