频道分类

Delphi 获取计算机串口列表

作者:admin 来源: 日期:2019/10/12 15:44:51 人气: 标签:

 
 
procedure GetSysSerialComm(CommLst: TStrings);
var
  reg: TRegistry;
  ComList: TStringList;
  i: Integer;
begin
  ComList:= TStringList.Create;
  reg:= TRegistry.Create;
  CommLst.Clear;
  try
    reg.RootKey:= HKEY_LOCAL_MACHINE;
    if reg.OpenKey('HARDWARE\DEVICEMAP\SERIALCOMM', false) then
    begin
      reg.GetValueNames(ComList);
      for i:= 0 to ComList.Count -1 do
        CommLst.Add(reg.ReadString(ComList[i]));
    end;
  finally
    ComList.Free;
    reg.Free;
  end;
end;
 
//调用示例
procedure TForm1.btn1Click(Sender: TObject);
begin
  GetSysSerialComm(cbb1.Items);
end;

来源:https://blog.csdn.net/liang08114/article/details/86712626