[Lazarus] Lazarus does not find compiled package, why?
Bo Berglund
bo.berglund at gmail.com
Mon Oct 31 00:48:51 CET 2022
On Mon, 31 Oct 2022 00:32:50 +0100, Werner Pamler via lazarus
<lazarus at lists.lazarus-ide.org> wrote:
>Am 30.10.2022 um 19:42 schrieb Bo Berglund via lazarus
>> When I am at it:
>> Is there a way on Windows to enumerate the existing serial ports so I can put a
>> selector list on the form?
>
>I have the following code in one of my projects (Windows-only). It
>creates a comma-separated list to assigned to a ComboBox.Items.CommaText
>
>function GetSerialPortNames: string;
>var
> reg: TRegistry;
> l, v: TStringList;
> n: integer;
>begin
> l := TStringList.Create;
> v := TStringList.Create;
> reg := TRegistry.Create;
> try
> reg.Access := KEY_READ;
> reg.RootKey := HKEY_LOCAL_MACHINE;
> reg.OpenKey('\HARDWARE\DEVICEMAP\SERIALCOMM', false);
> reg.GetValueNames(l);
> for n := 0 to l.Count - 1 do
> v.Add(PChar(reg.ReadString(l[n])));
> Result := v.CommaText;
> finally
> reg.Free;
> l.Free;
> v.Free;
> end;
>end;
Thanks, I used the registry way since it was not so hard to do and this will
only be a Windows app.
function THanSimulatorMain.ListSerialPorts(LS: TStrings): integer;
var
I:integer;
reg:tregistry;
begin
Reg := TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKeyReadOnly('HARDWARE\DEVICEMAP\SERIALCOMM') then
begin
LS.Clear;
Reg.GetValueNames(LS);
for I := 0 to LS.Count - 1 do
LS[i] := Reg.ReadString(LS[i]);
end;
Result := LS.Count;
finally
Reg.Free;
end;
end;
--
Bo Berglund
Developer in Sweden
More information about the lazarus
mailing list