1.<br>procedure TJeffsForm.GetAvailableComPorts();<br>var<br> i : Integer;<br> S : String;<br> ComName: array[0..9] of Char;<br> TheComHandle: Integer;<br><br>begin<br><br> (*<br> ** Okay, Clear everything in the PortsComboBox because<br> ** we want to start off fresh.<br> *)<br><br> PortsComboBox.Clear();<br><br> (*<br> ** Windows 95/98 can only handle up to 50 COM ports.<br> ** All we are doing here is checking to see if Windows<br> ** "can" open up the COM port. If so, then we know it's<br> ** available. And so we add it to our ComboBox list<br> ** and of course close the COM port each time we check it.<br> *)<br><br> for i := 1 to 50 do begin<br><br> StrFmt( ComName, '//./COM%d', );<br><br> TheComHandle := CreateFile<br> (<br> ComName, // name<br> GENERIC_READ or GENERIC_WRITE, // access attributes<br> 0, // no sharing<br> nil, // no security<br> OPEN_EXISTING, // creation action<br> FILE_ATTRIBUTE_NORMAL or<br> FILE_FLAG_OVERLAPPED, // attributes<br> 0 // no template<br> );<br><br> if ( TheComHandle <> INVALID_HANDLE_VALUE ) then begin<br><br> S := Format('COM%d', );<br> PortsComboBox.Items.Add(S);<br><br> end;<br><br> CloseHandle( TheComHandle );<br><br> end; {end of for loop}<br><br>end;<br>2.<br>procedure TForm1.Button1Click(Sender: TObject); <br>var <br>reg : TRegistry; <br>ts : TStrings; <br>i : integer; <br>begin <br>reg := TRegistry.Create; <br>reg.RootKey := HKEY_LOCAL_MACHINE; <br>reg.OpenKey('hardware/devicemap/serialcomm', <br>false); <br>ts := TStringList.Create; <br>reg.GetValueNames(ts); <br>for i := 0 to ts.Count -1 do begin <br>Memo1.Lines.Add(reg.ReadString(ts.Strings)); <br>end; <br>ts.Free; <br>reg.CloseKey; <br>reg.free; <br>end;