Fonts in derart Schleifen anzulegen macht keinen Sinn.
Um dein konkretes Problem mit dem fehlerhaften LoadFont zu bearbeiten, brauchen wir mehr von deinem Code.
Meistens liegt das Problem nämlich nicht im eigentlichen Aufruf?????
Ich habe mal ein Code-Beispiel aus der Hilfe angepasst. (Ich nutze immer EnableExplicit, die Beispiele leider nie!)
Außerdem ist bei mir alles Procedure orientiert, damit ich auf globale Variablen verzichten kann (so weit es geht).
Und noch ein paar Tipps (ungefragt)
Der Standard Datentyp ist Integer (beste Wahl) Syntax: Global g_IntVar oder Protected IntVar kann natürlich auch IntVar.i geschrieben werden.
Unter Windows muss nur selten auf Word oder Long zurückgegriffen werden.
Mit Result = IsFont(#Font) kann man auch gut abprüfen ob die Variable richtig initialisiert ist. (siehe Beispiel)
Dabei sind die Proceduren bspw. (IsGadget, IsWindow, etc.) gefahrlos anzuwenden.
Code: Alles auswählen
EnableExplicit
;-== Debug Helper Functions ==-----------------------------------------------------------------
Macro DQ ;' Double Quotes " for macros
"
EndMacro
Macro InspectInteger(iValue)
" " + DQ#iValue#DQ + " = 0x" + Hex(iValue) + " (" + Str(iValue) + "); "
EndMacro
Macro DebugInspectInteger(iValue)
Debug InspectInteger(iValue)
EndMacro
;-== Example from Help ==----------------------------------------------------------------------
Procedure main()
Protected Font1, Font2 ;' == Integer as default
Protected UsedFont.w ;' == Word
Protected Event ;' == Integer (why not)
Debug "SizeOf Font1 = " + SizeOf(Font1) + " bytes"
Debug "SizeOf Font2 = " + SizeOf(Font2) + " bytes"
Debug "SizeOf UsedFont = " + SizeOf(UsedFont) + " bytes"
If OpenWindow(0, 0, 0, 320, 130, "FontID() Example", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(0, 10, 10, 300, 30, "Click to change the font")
Font1 = LoadFont(#PB_Any, "Arial" , 8, #PB_Font_Bold)
Font2 = LoadFont(#PB_Any, "Verdana", 12, #PB_Font_StrikeOut)
UsedFont = 1
If IsFont(Font1) And IsFont(Font2)
DebugInspectInteger(Font1) ;' Value of Font
DebugInspectInteger(Font2)
Else
Debug "Font not defined;"
EndIf
Repeat
Event = WaitWindowEvent()
If Event = #PB_Event_Gadget
If EventGadget() = 0
If UsedFont = 1
SetGadgetFont(0, FontID(Font2))
UsedFont = 2
Else
SetGadgetFont(0, FontID(Font1))
UsedFont = 1
EndIf
EndIf
EndIf
Until Event = #PB_Event_CloseWindow
EndIf
EndProcedure
main()