source: CommOptionsForm/USerialPortOptions.pas

Last change on this file was 21, checked in by george, 14 years ago
  • Přidáno: Formulář nastavení sériového portu pro Lazarus.
File size: 2.9 KB
Line 
1unit USerialPortOptions;
2
3{$mode objfpc}{$H+}
4
5interface
6
7uses
8 Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
9 StdCtrls, ExtCtrls, USerialPort;
10
11type
12
13 { TSerialPortOptions }
14
15 TSerialPortOptions = class(TForm)
16 Bevel1: TBevel;
17 ButtonSet: TButton;
18 ButtonCancel: TButton;
19 CheckBoxDTR: TCheckBox;
20 Label7: TLabel;
21 CheckBoxRTS: TCheckBox;
22 ComboBox1: TComboBox;
23 ComboBox2: TComboBox;
24 ComboBox3: TComboBox;
25 ComboBox4: TComboBox;
26 ComboBox5: TComboBox;
27 ComboBox6: TComboBox;
28 Label1: TLabel;
29 Label2: TLabel;
30 Label3: TLabel;
31 Label4: TLabel;
32 Label5: TLabel;
33 Label6: TLabel;
34 procedure ButtonSetClick(Sender: TObject);
35 procedure ButtonCancelClick(Sender: TObject);
36 procedure ComboBox3Change(Sender: TObject);
37 procedure FormShow(Sender: TObject);
38 private
39 { private declarations }
40 public
41 SerialPort: TSerialPort;
42 end;
43
44var
45 SerialPortOptions: TSerialPortOptions;
46
47implementation
48
49{ TSerialPortOptions }
50
51procedure TSerialPortOptions.ButtonSetClick(Sender: TObject);
52begin
53 with SerialPort do begin
54 Active := False;
55 if ComboBox1.Items.Count = 0 then Name := ''
56 else Name := ComboBox1.Items[ComboBox1.ItemIndex];
57 BaudRate := TBaudRate(ComboBox2.ItemIndex);
58 Parity := TParity(ComboBox3.ItemIndex);
59 DataBits := ComboBox4.ItemIndex + 4;
60 StopBits := TStopBits(ComboBox5.ItemIndex);
61 FlowControl := TFlowControl(ComboBox6.ItemIndex);
62 RTS := CheckBoxRTS.Checked;
63 DTR := CheckBoxDTR.Checked;
64 Active := True;
65 end;
66 Close;
67end;
68
69procedure TSerialPortOptions.ButtonCancelClick(Sender: TObject);
70begin
71 Close;
72end;
73
74procedure TSerialPortOptions.ComboBox3Change(Sender: TObject);
75begin
76
77end;
78
79procedure TSerialPortOptions.FormShow(Sender: TObject);
80var
81 I: Integer;
82 TestPort: TSerialPort;
83// Index: Integer;
84begin
85 SerialPort.Active := False;
86 TestPort := TSerialPort.Create;
87 ComboBox1.Clear;
88 for I := 1 to 255 do with TestPort do begin
89 Name := 'COM' + IntToStr(I);
90 Active := True;
91 if Active or ((Name = SerialPort.Name) and (SerialPort.Active)) then begin
92 ComboBox1.AddItem('COM' + IntToStr(I), TObject(I));
93 if Name = SerialPort.Name then
94 ComboBox1.ItemIndex := ComboBox1.Items.Count - 1;
95 end;
96 Active := False;
97 end;
98 TestPort.Free;
99 SerialPort.Active := True;
100
101 if (ComboBox1.Items.Count > 0) and (ComboBox1.ItemIndex = -1) then
102 ComboBox1.ItemIndex := 0;
103
104 with SerialPort do begin
105 ComboBox2.ItemIndex := Integer(BaudRate);
106 ComboBox3.ItemIndex := Integer(Parity);
107 ComboBox4.ItemIndex := Integer(DataBits) - 4;
108 ComboBox5.ItemIndex := Integer(StopBits);
109 ComboBox6.ItemIndex := Integer(FlowControl);
110 CheckBoxRTS.Checked := RTS;
111 CheckBoxDTR.Checked := DTR;
112 end;
113end;
114
115initialization
116 {$I USerialPortOptions.lrs}
117
118end.
119
Note: See TracBrowser for help on using the repository browser.