Current File

Everything else that doesn't fall into one of the other PB categories.
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Current File

Post by dmoc »

Is there anyway to determine the current file number as set by CreateFile() or UseFile()? Tracking the current file number becomes difficult with nested calls and trying to modularise code (not to mention the problem of avoiding re-using file numbers). It would be great if PB had the following (simple?) function:

f = CurrentFileNumber()
freak
PureBasic Team
PureBasic Team
Posts: 5946
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

Code: Select all

Procedure.l CurrentFileNumber()
  Protected *Pointer.LONG, Current.l, MaxFile.l, Number.l, Result.l
  !extrn _PB_File_ObjectsNumber
  !extrn _PB_File_ObjectsArea    
  !extrn _PB_File_Current   
  
  !mov eax, [_PB_File_ObjectsArea]
  !mov [esp], eax
  !mov eax, [_PB_File_Current]
  !mov [esp+4], eax
  !mov eax, [_PB_File_ObjectsNumber]
  !mov [esp+8], eax

  Result = -1
  For Number = 0 To MaxFile-1
    If *Pointer\l = Current And *Pointer\l <> 0
      Result = Number
    EndIf
    *Pointer + 4
  Next Number
  
  ProcedureReturn Result
EndProcedure
Returns -1, if there is no current file.

Timo
quidquid Latine dictum sit altum videtur
dmoc
Enthusiast
Enthusiast
Posts: 739
Joined: Sat Apr 26, 2003 12:40 am

Post by dmoc »

Timo = *

Cheers!
Post Reply