1 | unit UCommOptionsForm;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
---|
7 | Dialogs, StdCtrls, CommPort, ExtCtrls;
|
---|
8 |
|
---|
9 | type
|
---|
10 | TCommOptionsForm = class(TForm)
|
---|
11 | Label1: TLabel;
|
---|
12 | ComboBox1: TComboBox;
|
---|
13 | Label2: TLabel;
|
---|
14 | ComboBox2: TComboBox;
|
---|
15 | Label3: TLabel;
|
---|
16 | ComboBox3: TComboBox;
|
---|
17 | ComboBox4: TComboBox;
|
---|
18 | Label4: TLabel;
|
---|
19 | Label5: TLabel;
|
---|
20 | ComboBox5: TComboBox;
|
---|
21 | ComboBox6: TComboBox;
|
---|
22 | Label6: TLabel;
|
---|
23 | Button1: TButton;
|
---|
24 | Button2: TButton;
|
---|
25 | Bevel1: TBevel;
|
---|
26 | procedure Button2Click(Sender: TObject);
|
---|
27 | procedure Button1Click(Sender: TObject);
|
---|
28 | private
|
---|
29 | CommPort: TCommPort;
|
---|
30 | public
|
---|
31 | procedure ShowForm(CommPort: TCommPort);
|
---|
32 | end;
|
---|
33 |
|
---|
34 | var
|
---|
35 | CommOptionsForm: TCommOptionsForm;
|
---|
36 |
|
---|
37 | implementation
|
---|
38 |
|
---|
39 | uses UMainForm;
|
---|
40 |
|
---|
41 | {$R *.dfm}
|
---|
42 |
|
---|
43 | procedure TCommOptionsForm.Button1Click(Sender: TObject);
|
---|
44 | begin
|
---|
45 | with CommPort do begin
|
---|
46 | Open := False;
|
---|
47 | if (ComboBox1.Items.Count > 0) and (ComboBox1.ItemIndex <> -1) then
|
---|
48 | ComNumber := StrToInt(Copy(ComboBox1.Items[ComboBox1.ItemIndex], 4, 3))
|
---|
49 | else ComNumber := 1;
|
---|
50 | BaudRate := TBaudRate(ComboBox2.ItemIndex);
|
---|
51 | Parity := TParity(ComboBox3.ItemIndex);
|
---|
52 | DataBits := TDataBits(ComboBox4.ItemIndex + 4);
|
---|
53 | StopBits := TStopBits(ComboBox5.ItemIndex);
|
---|
54 | FlowControl := TFlowControl(ComboBox6.ItemIndex);
|
---|
55 | Open := True;
|
---|
56 | end;
|
---|
57 | Close;
|
---|
58 | end;
|
---|
59 |
|
---|
60 | procedure TCommOptionsForm.Button2Click(Sender: TObject);
|
---|
61 | begin
|
---|
62 | Close;
|
---|
63 | end;
|
---|
64 |
|
---|
65 | procedure TCommOptionsForm.ShowForm(CommPort: TCommPort);
|
---|
66 | var
|
---|
67 | I: Integer;
|
---|
68 | TestPort: TCommPort;
|
---|
69 | // Index: Integer;
|
---|
70 | begin
|
---|
71 | Self.CommPort := CommPort;
|
---|
72 | TestPort := TCommPort.Create(nil);
|
---|
73 | ComboBox1.Clear;
|
---|
74 | for I := 1 to 255 do with TestPort do begin
|
---|
75 | ComNumber := I;
|
---|
76 | Open := True;
|
---|
77 | if Open or ((I = CommPort.ComNumber) and (CommPort.Open)) then begin
|
---|
78 | ComboBox1.AddItem('COM' + IntToStr(I), Pointer(I));
|
---|
79 | if I = CommPort.ComNumber then ComboBox1.ItemIndex := ComboBox1.Items.Count - 1;
|
---|
80 | end;
|
---|
81 | Open := False;
|
---|
82 | end;
|
---|
83 | TestPort.Free;
|
---|
84 |
|
---|
85 | with CommPort do begin
|
---|
86 | ComboBox2.ItemIndex := Integer(BaudRate);
|
---|
87 | ComboBox3.ItemIndex := Integer(Parity);
|
---|
88 | ComboBox4.ItemIndex := Integer(DataBits) - 4;
|
---|
89 | ComboBox5.ItemIndex := Integer(StopBits);
|
---|
90 | ComboBox6.ItemIndex := Integer(FlowControl);
|
---|
91 | end;
|
---|
92 | ShowModal;
|
---|
93 | end;
|
---|
94 |
|
---|
95 | end.
|
---|