Seite 1 von 1

PBOSL FastFile Ersatz (FileMapping)

Verfasst: 20.01.2006 14:44
von bobobo
Es hat sich herausgestellt, dass die FastFileFunktionen
aus PBOSL etwas buggy sind (laut kundiger Aussage
kommt der Stack in Tüdder (in Tüdder sein= durcheinander sein) )

folgendes männliche(!) Demo demonstriert Ersatz für
FastFileOpen() und FastFileClose()

Code: Alles auswählen

; rings 20.01.2006

Enumeration 
  #Window 
  #Ausgabe 
  #FFile 
  #Button 
EndEnumeration 
Procedure Papi() 
  File.s="Bibeltext.txt" ; darf ruhig gross sein
  handle=CreateFile_(File, #GENERIC_READ, 3, 0, 3, #OPEN_EXISTING ,0) 
  length=FileSize(File) 
  If handle 
    If length>0 
      MapHandle = CreateFileMapping_(handle, 0, 2, 0, length, 0) 
      If MapHandle 
        ViewHandle = MapViewOfFile_(MapHandle, 4, 0, 0, 0) 
        If ViewHandle 
          SendMessage_(GadgetID(#Ausgabe), #EM_LIMITTEXT, -1, 0) ;Extentd the editogadget 
          SendMessage_(GadgetID(#Ausgabe), #WM_SETTEXT, 0, Viewhandle) ;Place the Content 
          UnmapViewOfFile_(ViewHandle) 
        EndIf 
      EndIf 
      CloseHandle_(MapHandle)  ;okay, now close the Maphandle 
    EndIf 
  EndIf 
  CloseHandle_(handle);okay, now close the Filehandle 
EndProcedure 

OpenWindow(#Window,0,0,300,300,#PB_Window_SystemMenu|#PB_Window_MaximizeGadget|#PB_Window_MinimizeGadget|#PB_Window_SizeGadget,"test") 
CreateGadgetList(WindowID(#window)) 
Editorgadget=EditorGadget(#Ausgabe,0,0,WindowWidth(),WindowHeight()-20) 
ButtonGadget(#Button,0,WindowHeight()-20,WindowWidth(),20,"Nochmal") 


Papi() 
SendMessage_(GadgetID(#Ausgabe),#EM_SCROLL,#SB_BOTTOM,0);#SB_PAGEDOWN,0) 
While WindowEvent():Wend 


Debug "Anzahl der Aufrufe "+Str(count)+" wenn das Ding stehen bleibt das Programm über den Debugger stoppen!" 


ActivateGadget(#Ausgabe) 

Repeat 
  event=WaitWindowEvent() 
  GadgetID = EventGadgetID() 
  If Event = #PB_Event_SizeWindow 
    ResizeGadget(#Ausgabe,0, 0, WindowWidth(), WindowHeight()-20) 
    ResizeGadget(#Button, 0, WindowHeight()-20, WindowWidth()/2,20) 
    
  EndIf 
  
  If Event = #PB_EventGadget 
    
    If GadgetID = #Button 
    count+1 
    Debug "Anzahl der Aufrufe "+Str(count)+" wenn das Ding stehen bleibt das Programm über den Debugger stoppen!" 
      ClearGadgetItemList(#Ausgabe) 
      While WindowEvent():Wend 
      Delay(200) ;damit man was sieht 
      
      
      Papi() 
      
            
      SendMessage_(GadgetID(#Ausgabe),#EM_SCROLL,#SB_BOTTOM,0);#SB_PAGEDOWN,0) 
      While WindowEvent():Wend 
      
    EndIf 
    
  EndIf 
Until Event=#PB_Event_CloseWindow