Menu

#38 EnumComPorts and Unicode Delphi

open
nobody
None
5
2012-01-20
2012-01-20
No

EnumComPorts is not fully compatible in Unicode Delphi Versions.
It calls RegEnumValue() which retuns the length of the data in Bytes in DataLen.
The it uses the DataLen in a call:
SetLength(Data, DataLen - 1);
This only works in non-Unicode, as SetLength wants Characters, not Bytes. The resulting String will be twice as long in Unicode, with trailing garbage as the data is uninitialized.

Simple Workaround:
SetLength(Data, DataLen div sizeof(char) - 1);

Discussion