function TPCDataLink.GetAvailableCommPort:String;
var
I:Integer;
myhCommFile:THandle;
CommPort:String;
//count : Integer;
begin
Result := '';
//count := CommPortList.Count;
For I := 1 to 4 do
begin
CommPort := 'COM'+inttostr(I);
myhCommFile := CreateFile( PChar(CommPort),
GENERIC_READ or GENERIC_WRITE,
0, {not shared}
nil, {no security ??}
OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL or FILE_FLAG_OVERLAPPED,
0 {template} );
{$ifdef _Debug}
LogFileAddLine('Sync Manager is accessing Comm Port : '+CommPort);
{$endif}
if myhCommFile <> INVALID_HANDLE_VALUE then
begin
CloseHandle(myhCommFile);
if Result = '' then
Result := CommPort;
if CommPort = 'COM1' then
Com11.Enabled := True
else if CommPort = 'COM2' then
Com21.Enabled := True
else if CommPort = 'COM3' then
Com31.Enabled := True
else
Com41.Enabled := True;
exit;
end
else
begin
if CommPort = 'COM1' then
Com11.Enabled := False
else if CommPort = 'COM2' then
Com21.Enabled := False
else if CommPort = 'COM3' then
Com31.Enabled := False
else
Com41.Enabled := False;
end;
end;
end;