How to check return value of DWScript FileCreate function?

Using DWScript, I do not see an obvious way to check the return value of the FileCreate function.

Example (not working) script:

function TestFileCreate : Boolean; var F : File; begin F := FileCreate('MyTestFile.txt'); Result := (F = -1); // Not working! Result := (F.Handle = -1); // Not working! end; 

Extract from DWScript source code:

 procedure TFileCreateFunc.DoEvalAsVariant(const args : TExprBaseListExec; var result : Variant); var h : THandle; i : IdwsFileHandle; begin h:=FileCreate(args.AsFileName[0]); i:=TdwsFileHandle.Create(h); Result:=IUnknown(i); end; 

As you can see, Delphi CreateFile is called internally, and the result is -1 when it fails. This numeric value is converted to IdwsFileHandle.

+7
delphi dwscript
source share
1 answer

They should have created an exception in case of failure. Now it is fixed!

Extended, so now the exception is triggered only if an invalid file is used, with the exception of two functions: FileIsValid and FileClose. Helpers have also been added so that file functions can be used as methods (for example, "FileIsValid (f)" can also be written as "f.IsValid")

+2
source share

All Articles