Get Bluetooth com in delphi

function GetBlutoothComPort: String;
var S, S1: String;
Item: Integer;
Reg: TRegistry;
KeyList1, KeyList2: TStringList;

begin
Reg := TRegistry.Create;
if Reg = nil then begin
fmDebug.AddDebugItem( ‘Error creating Reg ‘ );
exit; end;
KeyList1 := TStringList.Create;
if KeyList1 = nil then begin
fmDebug.AddDebugItem( ‘Error creating KeyList1 ‘ );
exit; end;
KeyList2 := TStringList.Create;
if KeyList2 = nil then begin
fmDebug.AddDebugItem( ‘Error creating KeyList2 ‘ );
exit; end;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
S := ‘SYSTEMCurrentControlSetEnumBTHENUM’;
fmDebug.AddDebugItem( ‘Key: ‘ + S );
try
Reg.OpenKeyReadOnly(S);
Reg.GetKeyNames(KeyList1);
For Item := 0 to KeyList1.Count-1 do begin
S1 := KeyList1.Strings[Item];
Reg.OpenKeyReadOnly(S + S1);
Reg.GetKeyNames(KeyList2);
S1 := S + KeyList1.Strings[Item] + ” + KeyList2.Strings[0] +
‘Device Parameters’;
fmDebug.AddDebugItem( ‘Key: ‘ + S1 );
Reg.OpenKeyReadOnly(S1);
If Reg.ValueExists(‘RxFIFO’) then begin
S1 := Reg.ReadString(‘PortName’);
result := S1;
fmDebug.AddDebugItem( ‘Working Bluetooth Port determined: ‘ +
S1 );
break; end;
fmDebug.AddDebugItem( ‘Bluetooth Port detected: ‘ +
Reg.ReadString(‘PortName’) );
end;
except
fmDebug.AddDebugItem( ‘Error Bluetooth’ );
end;
finally
Reg.Free;
KeyList1.Free;
KeyList2.Free;
end;
end;

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.