If #file=CreateFile(#PB_Any,file$)
DeleteFile(file$)
EndIf
i dont really understand.. how it is working now (second method) - does it returns the handle or the counted constant, or the success of operation ? i would say the first way is the better one.
The Do or Die idiom is one approach. Unfortunately Fred has said that the approach works by accident and will not guarantee that the behaviour will remain: viewtopic.php?t=9926&start=15
Now that Purebasic is growing, and being applied to bigger projects then I cleaner syntax for handling errors and exceptions really is needed. How to do this without spoiling the simplicity is another matter.
Fred has promised Macros in 4. Perhaps that is the answer.
I can't quite work out what you are trying to achieve with the proposed syntax. As far as I can see, it removes the need to type an extra line (If ... verses Assign and then If ...) but introduces an implied function that creates a file handle:
If CreateFile(myfile.l=#PB_Any,file$)
Thereafter myFile is available for use with the file. However both the old and new (#PB_Any) methods provide a way to reference the file without having to introduce a new syntax. The new way requires one extra statement in the preceding examples.
handle=openfile(0,file$)
handle=openfile(#x,file$)
handle=openfile(#pb_any,file$)
;but which is the #fileconstant for closefile(?)
handle=#fileconstant=openfile(#pb_any,file$)
;and how is returned, if the file is succesfull opened ?
if handle=#fileconstant=openfile(#pb_any,file$) = 1 ???
; -- Original way gives results,
; result is file id, but references to the file
; are made with the value you used to open file.
result=OpenFile(0,file$)
UseFile(0)
CloseFile(0)
result=OpenFile(#x,file$)
UseFile(#x)
CloseFile(#x)
; -- New option -
; result is now the "handle" used to
; reference or, um, handle the file.
handle=OpenFile(#pb_any,file$)
UseFile(handle)
CloseFile(handle)
IMO the new or #PB_Any way for gadgets and objects means that there is now one less value to worry about. The "handle" is it.
In places where #PB_Any is valid usage (and this is as I understand it), if #PB_Any is used to establish an item, then a value is returned.
The returned value is then used whenever a reference to the item is required. The technical name for the returned value may be "handle" or "ID" or "banana", but whatever it is, that is how the item is referenced.
Using the original way, a value was used to establish an item, and another value was returned.
With the original method, sometimes the first value was required to identify the item to be used, and sometimes the second.
However, as I said, I am losing the plot, and I'm not exactly sure what we are discussing, so I will bow out now.