本文整理自网络,侵删。
var TotalComNum : Integer = 0; HaveOpenCom : string = '0';
USES Registry;
procedure GetComListFromReg();var reg:TRegistry; // 注: 要引用Registry单元 Namelst:TStrings; i,j:integer; str:string; b:Boolean;begin Namelst:=TStringList.Create; reg:=TRegistry.Create; reg.RootKey :=HKEY_LOCAL_MACHINE; b := reg.OpenKey('HARDWARE\DEVICEMAP\SERIALCOMM',true); //ShowMessage('open ='+ BoolToStr(b)); reg.GetValueNames(Namelst); //Form1.memo1.Clear; //for i := 0 to Namelst.Count-1 do // Form1.memo1.Lines.Add(reg.ReadString(Namelst[i])); //ShowMessage('namelst = ' + IntToStr(Namelst.Count) + 'totalcomnum = ' + IntToStr(TotalComNum)); if Namelst.Count <> TotalComNum then begin TotalComNum := Namelst.Count; if HaveOpenCom = '0' then begin //ShowMessage('123'); Form8.ComboBox1.Items.Clear; for i := 0 to Namelst.Count-1 do begin //ShowMessage(reg.ReadString(Namelst[i])); Form8.ComboBox1.Items.Add(reg.ReadString(Namelst[i])); end; // 排序 for i := 0 to Namelst.Count-2 do for j := i+1 to Namelst.Count-1 do if Form8.ComboBox1.Items[i] > Form8.ComboBox1.Items[j] then begin str := Form8.ComboBox1.Items[i]; Form8.ComboBox1.Items[i] := Form8.ComboBox1.Items[j]; Form8.ComboBox1.Items[j] := str; end; Form8.ComboBox1.itemindex := 0; end else begin //ShowMessage('456'); //ShowMessage('*******'+ HaveOpenCom); for i := 0 to Namelst.Count-1 do begin //ShowMessage('-------' + reg.ReadString(Namelst[i])); if HaveOpenCom = reg.ReadString(Namelst[i]) then begin reg.CloseKey; reg.Free; Namelst.Free; Exit; //break; end; end; //ShowMessage('i=' + IntToStr(i) + 'count=' + IntToStr(Namelst.Count)); if i = Namelst.Count then begin //ShowMessage('close'); // Form8.Button1.Click; end; //ShowMessage('***i=' + IntToStr(i) + 'count=' + IntToStr(Namelst.Count)); end; end; reg.CloseKey; reg.Free; Namelst.Free;end;
procedure TForm8.FormCreate(Sender: TObject);beginGetComListFromReg();end;
相关阅读 >>
Delphi xe listbox 行高根据内容高度进行调速
Delphi 双击listbox1内容,数据插入到memo1/synedit1鼠标指定位置
Delphi 使用泛型的 tarray 从动态数组中查找指定元素
Delphi twebbrowser流程讲解及如何判断下载网页成功
Delphi ini文件操作 tinifile、tmeminifile
更多相关阅读请进入《Delphi》频道 >>