Code: Alles auswählen
;Beispiel für Parameterübergabe von Listen an Unterprogramme
;Beispiel für Errechnung der Indizes im Scrollgadget
;Beispiel für With und Endwith
;DIES SOLLTE ALLE DEINE FRAGEN BEANTWORTEN
;UND IST EIN GUTES BEISPIEL FÜR DIE NEUERUNGEN VON PB$
; DANKE FRED!
Structure TableLine
index.l
y.l
yl.l
EndStructure
Structure TableColumn
x.l
y.l
xl.l
yl.l
name.s
id.l
EndStructure
Structure Gad
x.l
y.l
b.l
h.l
Gadgetart.l
Spalte.l
Zeile.l
Nummer.l
EndStructure
Enumeration
#Window_0
EndEnumeration
Global GGAD.l
Global GWB.l
Global GWH.l
Procedure PlusGadget(gadgetnummer.l,x.l,y.l,h.l,b.l,zeile.l,spalte.l,G.gad())
GGAD.l + 1
SetGadgetData(gadgetnummer.l,GGAD.l)
AddElement(G())
With G()
\Nummer=gadgetnummer.l :\x=x.l : \y=y.l :\h=h.l : \b=b.l :\Gadgetart=GadgetType(gadgetnummer)
\zeile=zeile.l : \spalte=spalte.l
EndWith
EndProcedure
Procedure TableGadget(GadgetNr,x,y,width,height,name$,SpaltenBreite,TLL.TableLine(),TCL.TableColumn(),G.gad())
If CreateGadgetList(WindowID(#Window_0))
ScrollAreaGadget(GadgetNr, x, y, width, height, 80, 20, 15, #PB_ScrollArea_Single)
plusgadget(Gadgetnr,x,y,width,height,-1,-1,G())
AddElement(TLL()) ;Neue Zeile
AddElement(TCL()) ;Neue Spalte
With TCL()
\x=30 : \y=0 : \xl=SpaltenBreite :\yl=20 :\name=name$
\id=ButtonGadget(#PB_Any, \x, \y, \xl, \yl, \name, #PB_Button_MultiLine)
plusgadget(\id,\x,\y,\xl,\yl,0,1,G())
EndWith
CloseGadgetList()
EndIf
EndProcedure
Procedure AddTableColumn(GadgetNr,Position,name$,Breite,TCL.TableColumn(),G.Gad())
OpenGadgetList(GadgetNr)
istbreite=GetGadgetAttribute(GadgetNr,#PB_ScrollArea_InnerWidth)
SetGadgetAttribute(GadgetNr,#PB_ScrollArea_InnerWidth,Breite+istbreite)
LastElement(TCL())
With TCL()
x = \x : y = \y :xl= \xl : yl= \yl
AddElement(TCL())
\x=x+xl : \y=y : \xl=Breite : \yl=yl : \name=name$
\id=ButtonGadget(#PB_Any, \x, \y, \xl,\yl,\name, #PB_Button_MultiLine)
plusgadget(\id,\x,\y,\xl,\yl,0,CountList(TCL()),G())
EndWith
CloseGadgetList()
EndProcedure
;Nun kann man Unterprogramme schreiben die allgemein gültig sind!
Procedure AddTableLine(GadgetNr,TLL.TableLine(),TCL.TableColumn(),G.gad())
OpenGadgetList(GadgetNr)
isthoehe=GetGadgetAttribute(GadgetNr,#PB_ScrollArea_InnerHeight)
SetGadgetAttribute(GadgetNr,#PB_ScrollArea_InnerHeight,15+isthoehe)
Spaltenanzahl = CountList(TCL())
LastElement(TLL())
With TLL()
index=\index : y=\y : yl=\yl
AddElement(TLL())
\index=index+1 : \y=y+yl :\yl=15
indextaste=ButtonGadget(#PB_Any,0,\y+20,30,15,Str(\index))
plusgadget(indextaste,0,\y+20,30,15, \index ,0,G())
EndWith
ForEach TCL()
With TCL()
x=\x :y=\yl+TLL()\y : xl=\xl : yl=TLL()\yl
EndWith
mp=StringGadget(#PB_Any,x,y,xl-2,yl-1,"",#ES_MULTILINE|#PB_String_BorderLess)
plusgadget(mp,x,y , xl-2 , yl-1 , CountList(TLL())-1 , ListIndex(tcl())+1 , G() )
;#PB_String_MultiLine gibts nicht mehr, #ES_MULTILINE scheint identisch zu sein
Next
CloseGadgetList()
EndProcedure
Procedure SaveTable()
EndProcedure
Procedure LoadTable()
EndProcedure
Procedure Open_Window_0(YTableLineList.TableLine(),XTableColumnList.TableColumn(),G.gad())
GWB.l=459:GWH.l=285
If OpenWindow(#Window_0, 74, 19, GWB.l, GWH.l,"TableGadget" , #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar)
TableGadget(1,5,5,300,200,"Index",50,YTableLineList(),XTableColumnList(),G())
AddTableColumn(1,0,"Bemerkung",100, XTableColumnList(),G())
AddTableColumn(1,0,"NotizAnweisung",100,XTableColumnList(),G())
AddTableColumn(1,0,"Bemerkung",100, XTableColumnList(),G())
AddTableColumn(1,0,"Bemerkung2",100, XTableColumnList(),G())
; CallDebugger
For xxx= 1 To 50
AddTableLine(1,YTableLineList(),XTableColumnList(),G())
Next
EndIf
EndProcedure
;Du siehst die Listen sind nicht global trotzdem werden sie in den Unterprogrammen verwendet!
NewList TableColumnList.TableColumn()
NewList TableLineList.TableLine()
NewList gadgets.gad()
Open_Window_0(TableLineList(),TableColumnList(),gadgets())
Repeat
Event = WaitWindowEvent()
EventType = EventType()
Select event ;EventType
Case #PB_Event_Gadget
GadgetID = EventGadget()
D=GetGadgetData(gadgetid)
SelectElement(gadgets(),D-1)
Debug "("+Str(gadgets()\zeile)+","+Str(gadgets()\spalte)+")"
Case #PB_Event_Repaint
If IsWindow(0) :UpdateWindow_(WindowID(0)) :EndIf
Debug "Repaint"
Case #WM_SIZE
nwh.l=WindowHeight(0) :nwb.l=WindowWidth(0)
If nwh.l<>GWH.l Or nwb.l<>GWB.l
ResizeGadget(1, 5*nwb.l/GWB.l , 5*nwh.l/GWH.l, 300*nwb.l/GWB.l , 200*nwh.l/GWH.l)
ForEach gadgets()
With gadgets()
EndWith
Next
Debug "Size"
EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
End