//-----------------------------------------------------------
function TRs232.GetPorts(var APorts: TStringList): integer;
var
KeyHandle: HKEY;
ErrCode, Index: Integer;
ValueName, Data: string;
ValueLen, DataLen, ValueType: DWORD;
TmpPorts: TStringList;
begin
Result := 0 ;
ErrCode := RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
'HARDWARE\DEVICEMAP\SERIALCOMM',
0,
KEY_READ,
KeyHandle);
if ErrCode = ERROR_SUCCESS then //설치된 포트 없음
begin
TmpPorts := TStringList.Create() ;
try
Index := 0;
repeat
ValueLen := 256;
DataLen := 256;
SetLength(ValueName, ValueLen);
SetLength(Data, DataLen);
ErrCode := RegEnumValue(
KeyHandle,
Index,
PChar(ValueName),
{$IFDEF DELPHI_4_OR_HIGHER}
Cardinal(ValueLen),
{$ELSE}
ValueLen,
{$ENDIF}
nil,
@ValueType,
PByte(PChar(Data)),
@DataLen);
if ErrCode = ERROR_SUCCESS then
begin
SetLength(Data, DataLen);
TmpPorts.Add(Data);
Inc(Index);
end ;
until (ErrCode <> ERROR_SUCCESS) ;
TmpPorts.Sort; //리스트 소트
Ports.Assign(TmpPorts);
Result := TmpPorts.Count;
finally
RegCloseKey(KeyHandle);
TmpPorts.Free() ;
end;
end
else
begin
Exception.Create('No Insatalled Comport at This System');
end ;
end;
function TRs232.GetPorts(var APorts: TStringList): integer;
var
KeyHandle: HKEY;
ErrCode, Index: Integer;
ValueName, Data: string;
ValueLen, DataLen, ValueType: DWORD;
TmpPorts: TStringList;
begin
Result := 0 ;
ErrCode := RegOpenKeyEx(
HKEY_LOCAL_MACHINE,
'HARDWARE\DEVICEMAP\SERIALCOMM',
0,
KEY_READ,
KeyHandle);
if ErrCode = ERROR_SUCCESS then //설치된 포트 없음
begin
TmpPorts := TStringList.Create() ;
try
Index := 0;
repeat
ValueLen := 256;
DataLen := 256;
SetLength(ValueName, ValueLen);
SetLength(Data, DataLen);
ErrCode := RegEnumValue(
KeyHandle,
Index,
PChar(ValueName),
{$IFDEF DELPHI_4_OR_HIGHER}
Cardinal(ValueLen),
{$ELSE}
ValueLen,
{$ENDIF}
nil,
@ValueType,
PByte(PChar(Data)),
@DataLen);
if ErrCode = ERROR_SUCCESS then
begin
SetLength(Data, DataLen);
TmpPorts.Add(Data);
Inc(Index);
end ;
until (ErrCode <> ERROR_SUCCESS) ;
TmpPorts.Sort; //리스트 소트
Ports.Assign(TmpPorts);
Result := TmpPorts.Count;
finally
RegCloseKey(KeyHandle);
TmpPorts.Free() ;
end;
end
else
begin
Exception.Create('No Insatalled Comport at This System');
end ;
end;