Page 1 of 1

Current File

Posted: Mon Sep 22, 2003 1:16 pm
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()

Posted: Mon Sep 22, 2003 2:33 pm
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

Posted: Mon Sep 22, 2003 2:49 pm
by dmoc
Timo = *

Cheers!