Result=FreeID() ;Result' contains the next free logical #ID
I manage me momentary with following routine:
Code: Select all
Global FreeID$
Procedure.l FreeID(Nr)
; Gives the next free (1-65536) logical ID (for Files etc.) back
; Managed become the ID's in the GLOBAL 'FreeID$' (!Important!)
;
; Nr = 0 deliver the next available logical ID
; Nr<> 0 again freely the ID "Nr"
;
; Result<0 no free ID available
; Result>0 contains a free logical ID
Protected Result
Nr=Abs(Nr)
Result=0
If Nr=0
; still NOTHING distribute ?
If Len(FreeID$)=0
; Each with "X" covered byte represents a distributed FreeID
FreeID$="X"
ProcedureReturn 1
Else
; all ID's distribute ?
If Len(FreeID$)=65536: ProcedureReturn -1: EndIf
; look for next free place
Result=FindString(FreeID$,"O",1)
If Result=0
; no free place found ?; String expand
FreeID$+"X": Result=Len(FreeID$)
Else
; ID newly distribute
FreeID$=Left(FreeID$,Result-1)+"X"+Right(FreeID$,Len(FreeID$)-Result)
EndIf
ProcedureReturn Result
EndIf
Else
If Nr>0 And Nr<=Len(FreeID$)
; release ID again
FreeID$=Left(FreeID$,Nr-1)+"O"+Right(FreeID$,Len(FreeID$)-Nr)
EndIf
EndIf
EndProcedure
it's sufficiently memory here
