Aber schon der Open-Aufruf über die API-Funktion CreateFile endet mit einer Exception zur Laufzeit

Kann mir jemand mal einen Tipp geben, was an diesem Code-Schnippsel falsch ist:
Code: Alles auswählen
var
hlf : String[4];
z_com : String;
z_dcb : String;
begin
if (port < 1) or (port > 9) then
begin
Result := False;
Exit;
end;
Str(port, hlf);
z_com := 'COM' + hlf;
hdl := CreateFile(PChar(z_com), // pointer to name of the file
GENERIC_READ or GENERIC_WRITE,// access (read-write) mode
0, // share mode (0=DenayAll)
Nil, // pointer to security attributes
OPEN_EXISTING, // how to create
FILE_ATTRIBUTE_NORMAL,// file attributes
0 // handle to file with attributes to copy
);