Null
Übersicht

MatheBetreff: Null |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Hallo,
ich habe ein kleines Problem ich wollte eine kleine GUI schreiben um mich mal wieder in BM einzuarbeiten, aber ich hab da ein kleines Problem mit Null. Code: [AUSKLAPPEN] Global GUI_Button:TButton[]
Global GUI_ButtonCount = -1 Type TButton 'Standart Variablen Field btnText$ Field btnXPos%, btnYPos% Field btnWidth%, btnHeight% Field btnGroup% Field btnStyle% Field btnBtnColor$, btnTextColor$ 'Spezial Variablen Field btnVisible% Field btnEnable% Method New() DebugLog GUI_ButtonCount End Method End Type Function CreateButton(btnText$,btnXPos%, btnYPos%,btnWidth%,btnHeight%,btnGroup%=0,btnStyle%=0, btnBtnColor$="255,255,255",btnTextColor$="255,255,255") Local ID% = -1 'Hier steckt irgendwo der Fehler For Local x = 0 To GUI_ButtonCount If GUI_Button[x] = Null Then ID = x Exit EndIf Next If ID = -1 Then GUI_ButtonCount :+ 1 ID = GUI_ButtonCount GUI_Button = New TButton[GUI_ButtonCount+1] EndIf GUI_Button[ID] = New TButton GUI_Button[ID].btnText = btnText GUI_Button[ID].btnXPos = btnXPos GUI_Button[ID].btnYPos = btnYPos GUI_Button[ID].btnWidth = btnWidth GUI_Button[ID].btnHeight = btnHeight GUI_Button[ID].btnGroup = btnGroup GUI_Button[ID].btnStyle = btnStyle GUI_Button[ID].btnBtnColor = btnBtnColor GUI_Button[ID].btnTextColor = btnTextColort Return ID End Function Nun erstelle will ich drei Buttons erstellen! Code: [AUSKLAPPEN] btn1 = CreateButton("Test01.Example",100,100,100,25)
btn2 = CreateButton("Test02.Example",500,450,100,25) btn3 = CreateButton("Test03.Example",300,300,100,25) Aber warum ist GUI_Button[1] Null ![]() Ich hoffe dass ihr mir helfen könnt. |
||
Windoof nein DANKE => ArchLinux ![]() |
- Zuletzt bearbeitet von Mathe am Sa, März 20, 2010 21:19, insgesamt einmal bearbeitet
![]() |
XeresModerator |
![]() Antworten mit Zitat ![]() |
---|---|---|
Arbeite mit SuperStrict.
Dein System verstehe ich auch nicht - wozu das Array, wenn du die IDs in extra variablen Speicherst? Die Such-schleife würde ich als Else Block von If ID = -1 Then verwenden. |
||
Win10 Prof.(x64)/Ubuntu 16.04|CPU 4x3Ghz (Intel i5-4590S)|RAM 8 GB|GeForce GTX 960
Wie man Fragen richtig stellt || "Es geht nicht" || Video-Tutorial: Sinus & Cosinus THERE IS NO FAIR. THERE IS NO JUSTICE. THERE IS JUST ME. (Death, Discworld) |
![]() |
mpmxyz |
![]() Antworten mit Zitat ![]() |
---|---|---|
BlitzMax: [AUSKLAPPEN] GUI_Button = New TButton[GUI_ButtonCount+1] Hier erstellst du ein neues leeres Array. Dann setzt du einen Wert. -> Alles andere ist Null. Nutzete stattdessen das: BlitzMax: [AUSKLAPPEN] GUI_Button:+New GUI_Button[1] Das vergrößert das Array um 1. BlitzMax: [AUSKLAPPEN] If GUI_Button[x] <> 0 ThenIch kann dir "Strict" nur wärmstens empfehlen! mfG mpmxyz |
||
Moin Moin!
Projekte: DBPC CodeCruncher Mandelbrot-Renderer |
- Zuletzt bearbeitet von mpmxyz am Mi, Apr 07, 2010 13:49, insgesamt einmal bearbeitet
![]() |
robotx |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ohne jetzt auf meine Vorposter einzugehen, liegt der Hauptfehler denke ich erst einmal hier:
Zitat: If GUI_Button[x] <> 0 Then
Das Array GUI_Button enthält Objekte vom Typ TButton und kann so nicht mit einer Integer verglichen werden. Also: Zitat: If GUI_Button[x] <> Null Then
Ansonsten habe ich noch nicht die Struktur des Quelltextes verstanden, was er überhaupt machen soll. Edit: Das hier soll nur ein kurzer Alternativvorschlag sein, den du vielleicht in Betracht ziehen könntest: Code: [AUSKLAPPEN] SuperStrict
Type TButton Global buttonList:TList = CreateList () Global buttonCount:Int 'Standart Variablen Field id:Int Field btnText:String Field btnXPos:Int, btnYPos:Int Field btnWidth:Int, btnHeight:Int Field btnGroup:Int Field btnStyle:Int Field btnBtnColor:String, btnTextColor:String 'Spezial Variablen Field btnVisible:Int Field btnEnable:Int Method New() DebugLog TButton.buttonCount End Method Function CreateButton:TButton (btnText$,btnXPos%,btnYPos%,btnWidth%,btnHeight%,btnGroup%=0, btnStyle%=0,btnBtnColor$="255,255,255",btnTextColor$="255,255,255") Local button:TButton = New TButton TButton.buttonCount = TButton.buttonCount + 1 button.id = buttonCount button.btnText = btnText button.btnXPos = btnXPos button.btnYPos = btnYPos button.btnWidth = btnWidth button.btnHeight = btnHeight button.btnGroup = btnGroup button.btnStyle = btnStyle button.btnBtnColor = btnBtnColor button.btnTextColor = btnTextColor TButton.buttonList.AddLast (button) Return button End Function End Type Local btn1:TButton = TButton.CreateButton("Test01.Example",100,100,100,25) Local btn2:TButton = TButton.CreateButton("Test02.Example",500,450,100,25) Local btn3:TButton = TButton.CreateButton("Test03.Example",300,300,100,25) |
||
- Zuletzt bearbeitet von robotx am Sa, März 20, 2010 21:27, insgesamt 3-mal bearbeitet
Mathe |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Danke jetzt funktioniert es ![]() Dieser Quelltext ist nur ein Teil der GUI er soll nur einen Button erstellen der später gezeichnet wird. Edit: Ich hab das mit einen Array gemacht weil ich keine Idee gehabt habe wie ich schnell einen Typeeintrag aufrufen kann. Es geht na leider nicht wie in BB wo man Handle verwenden kann. |
||
Windoof nein DANKE => ArchLinux ![]() |
Macintosh |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
meinButton.btnTex | ||
![]() |
robotx |
![]() Antworten mit Zitat ![]() |
---|---|---|
Um auf die Buttons zuzugreifen schreibst du dir einzelne get-Funktionen, welche die Buttons aus der Liste suchen und dir zurückliefern.
Beispiel: Code: [AUSKLAPPEN] SuperStrict
Graphics (800, 600) Type TButton Global buttonList:TList = CreateList () Global buttonCount:Int 'Standart Variablen Field id:Int Field btnText$ Field btnXPos%, btnYPos% Field btnWidth%, btnHeight% Field btnGroup% Field btnStyle% Field btnBtnColor$, btnTextColor$ 'Spezial Variablen Field btnVisible% Field btnEnable% Method New() DebugLog TButton.buttonCount End Method Function CreateButton:TButton (btnText$,btnXPos%,btnYPos%,btnWidth%,btnHeight%,btnGroup%=0,btnStyle%=0,btnBtnColor$="255,255,255",btnTextColor$="255,255,255") Local button:TButton = New TButton TButton.buttonCount = TButton.buttonCount + 1 button.id = buttonCount button.btnText = btnText button.btnXPos = btnXPos button.btnYPos = btnYPos button.btnWidth = btnWidth button.btnHeight = btnHeight button.btnGroup = btnGroup button.btnStyle = btnStyle button.btnBtnColor = btnBtnColor button.btnTextColor = btnTextColor TButton.buttonList.AddLast (button) Return button End Function Function getButton:TButton (id:Int) For Local button:TButton = EachIn TButton.buttonList If button.id = id Then Return button End If Next End Function Function getButtonByName:TButton (name:String) For Local button:TButton = EachIn TButton.buttonList If button.btnText = name Then Return button End If Next End Function Method drawButton () DrawRect (Self.btnXPos, Self.btnYPos, Self.btnWidth, Self.btnHeight) SetColor (0, 0, 0) DrawText (Self.btnText, Self.btnXPos + 5, Self.btnYPos + 5) SetColor (255, 255, 255) End Method End Type TButton.CreateButton("Test01.Example", 100, 100, 100, 25) TButton.CreateButton("Test02.Example", 500, 450, 100, 25) TButton.CreateButton("Test03.Example", 300, 300, 100, 25) DrawText ("Es werden alle Buttons gezeichnet. Press Key...", 10, 10) For Local button:TButton = EachIn TButton.buttonList button.drawButton () Next Flip Cls WaitKey () DrawText ("Es wird ein Button per ID ausgewählt und angezeigt. Press Key ...", 10, 10) TButton.getButton(1).drawButton () Flip Cls WaitKey () DrawText ("Es wird ein Button per Name ausgewählt und angezeigt. Press Key ...", 10, 10) TButton.getButtonByName("Test02.Example").drawButton () Flip WaitKey () Local a:Int = MilliSecs () Local b:TButton For Local n:Int = 0 To 300 DebugLog (n) b = TButton.getButton(1) Next Local c:Int = MilliSecs () DebugLog (c - a) 'Wie lange dauert es bei 300 Buttons in Millisekunden? (Theoretische Werte) |
||
www.botbomb.robotzgames.de
www.robotzgames.de |
Mathe |
![]() Antworten mit Zitat ![]() |
|
---|---|---|
Ah okey vielen dank.
mfg. Matthias |
||
Windoof nein DANKE => ArchLinux ![]() |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group