.
.
private
{ Private declarations }
procedure InitializeSerialPorts;
procedure WMDeviceChange(
Var Msg:TMessage);
message WM_DEVICECHANGE;
.
.
procedure TForm1.WMDeviceChange(
Var Msg:TMessage);
begin
if Msg.Msg=WM_DEVICECHANGE
then BEGIN
WindowsBeep(1000,50);
InitializeSerialPorts;
END;
end;
procedure TForm1.InitializeSerialPorts;
var
port:
string;
i: Integer;
config: TCommConfig;
cfsize: DWORD;
begin
for i := 1
to 16
do //MAX_NO_OF_SERIAL_PORTS
begin
if Components[i]
is TCheckbox
then TCheckbox(Components[i]).checked:=false;
port := Format('
COM%d', [i]);
cfsize := sizeof(config);
if GetDefaultCommConfig(PChar(port), config, cfsize)
then
case i
of
1: Checkbox1.checked:=true;
2: Checkbox2.checked:=true;
3: Checkbox3.checked:=true;
4: Checkbox4.checked:=true;
5: Checkbox5.checked:=true;
6: Checkbox6.checked:=true;
7: Checkbox7.checked:=true;
8: Checkbox8.checked:=true;
9: Checkbox9.checked:=true;
10: Checkbox10.checked:=true;
11: Checkbox11.checked:=true;
12: Checkbox12.checked:=true;
13: Checkbox13.checked:=true;
14: Checkbox14.checked:=true;
15: Checkbox15.checked:=true;
16: Checkbox16.checked:=true;
end;
end;
end;