New Problem

Just starting out? Need help? Post your questions and find answers here.
ClueLess
Enthusiast
Enthusiast
Posts: 360
Joined: Sun Jan 11, 2009 1:04 am

New Problem

Post by ClueLess »

Continue to develop the aplication and as I go new problems appear.

In this code The window open but does not show the ListIconGadget. It stays opened with the hourglass as if it was doing something.

Code: Select all

Enumeration FormWindow
  #ArtigosWindow
  #DB
EndEnumeration

Enumeration FormGadget
  #ArtigosList
  #But_Artigo_Delete
  #But_artigo_Select  
  #But_Cancel_Artigo_list
EndEnumeration

Procedure DeleteArtigo()
    NumeroArtigos = CountGadgetItems(#ArtigosList)
    For i = 0 To NumeroArtigos
      GetGadgetItemState(#ArtigosList, i)
      If #PB_Tree_Checked
        RemoveGadgetItem(#ArtigosList, i)
      EndIf
    Next
EndProcedure

Procedure FillArtigosList()
  
  DatabaseFile$ = "Facturacao.sqlite"
  UseSQLiteDatabase()
  
  If Not OpenDatabase(#DB, DatabaseFile$, "", "")
    MessageRequester("ERROR", "Can't open " + DatabaseFile$)
    End
  EndIf
  
  SQL.s = "SELECT * FROM Artigos"
  
  ClearGadgetItems(#ArtigosList)
    If DatabaseQuery(#DB, SQL)
    While NextDatabaseRow(#DB)
      CodigoArtigo.s = GetDatabaseString(#DB, 0)
      Descricao.s = GetDatabaseString(#DB, 1)
      PVP.i = GetDatabaseQuad(#DB, 7)
      
      AddGadgetItem(#ArtigosList, -1, CodigoArtigo + Chr(10) + Descricao +  Chr(10) + PVP) 
      
    Wend
    FinishDatabaseQuery(#DB)
  EndIf
  
  CloseDatabase(#DB)
  
  SetGadgetState(#ArtigosList, 0)
EndProcedure

OpenWindow(#ArtigosWindow, 0, 0, 1040, 500, "Artigos", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(#ArtigosList, 20, 20, 1000, 400, "Codigo", 150, #PB_ListIcon_CheckBoxes!#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#ArtigosList, 1, "Descrição", 696)
AddGadgetColumn(#ArtigosList, 2, "PVP", 150)
ButtonGadget(#But_Artigo_Delete, 800, 440, 100, 30, "Delete")
ButtonGadget(#But_Cancel_Artigo_list, 680, 440, 100, 30, "Cancel")
ButtonGadget(#But_artigo_Select, 920, 440, 100, 30, "Select")
    
FillArtigosList() 
  
Event = WaitWindowEvent()
If event = #PB_Event_Gadget
  If EventGadget() = #But_Artigo_Delete
    DeleteArtigo()
  ElseIf EventGadget() = #But_Cancel_Artigo_List
    Event = #PB_Event_CloseWindow  
  ElseIf EventGadget() = #But_artigo_Select
;      LimparFormArtigo() 
  EndIf
EndIf

 Repeat 
  Until Event = #PB_Event_CloseWindow

Can anyone help me find the problem?
I don't know how to attach a file so I can send the database

Thank You
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: New Problem

Post by jacdelad »

Please give your topics a meaningful title.

To your problem: You open the window, then do the database operation which may take time or not, I can't test. The event loop is entered when the database operation is done. Before entering the event loop, you cannot interact and no repainting is done. Try this code and tell us if the problem persists after the debug message is printed. If the debug message isn't printed, it means the database operation is still running and you have to wait.

Edit: I just saw your event loop was broken. I fixed that too! Look at the code, WaitWindowEvent has to be within the loop!!!! Maybe this already fixes your problem: You only processed one message.

Code: Select all

Enumeration FormWindow
  #ArtigosWindow
  #DB
EndEnumeration

Enumeration FormGadget
  #ArtigosList
  #But_Artigo_Delete
  #But_artigo_Select  
  #But_Cancel_Artigo_list
EndEnumeration

Procedure DeleteArtigo()
  NumeroArtigos = CountGadgetItems(#ArtigosList)
  For i = 0 To NumeroArtigos
    GetGadgetItemState(#ArtigosList, i)
    If #PB_Tree_Checked
      RemoveGadgetItem(#ArtigosList, i)
    EndIf
  Next
EndProcedure

Procedure FillArtigosList()
  
  DatabaseFile$ = "Facturacao.sqlite"
  UseSQLiteDatabase()
  
  If 0;Not OpenDatabase(#DB, DatabaseFile$, "", "")
    MessageRequester("ERROR", "Can't open " + DatabaseFile$)
    End
  EndIf
  
  SQL.s = "SELECT * FROM Artigos"
  
  ClearGadgetItems(#ArtigosList)
  If DatabaseQuery(#DB, SQL)
    While NextDatabaseRow(#DB)
      CodigoArtigo.s = GetDatabaseString(#DB, 0)
      Descricao.s = GetDatabaseString(#DB, 1)
      PVP.i = GetDatabaseQuad(#DB, 7)
      
      AddGadgetItem(#ArtigosList, -1, CodigoArtigo + Chr(10) + Descricao +  Chr(10) + PVP) 
      
    Wend
    FinishDatabaseQuery(#DB)
  EndIf
  
  CloseDatabase(#DB)
  
  SetGadgetState(#ArtigosList, 0)
EndProcedure

OpenWindow(#ArtigosWindow, 0, 0, 1040, 500, "Artigos", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ListIconGadget(#ArtigosList, 20, 20, 1000, 400, "Codigo", 150, #PB_ListIcon_CheckBoxes!#PB_ListIcon_GridLines|#PB_ListIcon_FullRowSelect)
AddGadgetColumn(#ArtigosList, 1, "Descrição", 696)
AddGadgetColumn(#ArtigosList, 2, "PVP", 150)
ButtonGadget(#But_Artigo_Delete, 800, 440, 100, 30, "Delete")
ButtonGadget(#But_Cancel_Artigo_list, 680, 440, 100, 30, "Cancel")
ButtonGadget(#But_artigo_Select, 920, 440, 100, 30, "Select")

FillArtigosList() 

Debug "Ready for interaction!"
Repeat 
  Event = WaitWindowEvent()
  If event = #PB_Event_Gadget
    If EventGadget() = #But_Artigo_Delete
      DeleteArtigo()
    ElseIf EventGadget() = #But_Cancel_Artigo_List
      Event = #PB_Event_CloseWindow  
    ElseIf EventGadget() = #But_artigo_Select
      ;      LimparFormArtigo() 
    EndIf
  EndIf
Until Event = #PB_Event_CloseWindow

Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: New Problem

Post by Kiffi »

:!: viewtopic.php?p=627971#p627971
Kiffi wrote: Thu Sep 19, 2024 8:01 pm @ClueLess: Please use meaningful subjects in future. Nobody can do anything with "Help", "A question" or "Can't find the error".
Hygge
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: New Problem

Post by Mindphazer »

Same error as in your post 2 days ago
Don't you read the answers we made ?????
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
ClueLess
Enthusiast
Enthusiast
Posts: 360
Joined: Sun Jan 11, 2009 1:04 am

Re: New Problem

Post by ClueLess »

@Mindphazer
Not the same problem
User avatar
jacdelad
Addict
Addict
Posts: 1992
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: New Problem

Post by jacdelad »

One more note: Process the EventType or your loop won't work as expected! You're not doing this now.

Possible Prototype:

Code: Select all

Repeat
  Select WaitWindowEvent()
    Case #PB_Event_CloseWindow
      Break
    Case #PB_Event_Gadget
      Select EventGadget()
        Case #MyGadget1
          Select EventType()
            Case #PB_EventType_LeftClick
              ;Do Something
          EndSelect
        Case #MyGadget2
          Select EventType()
            Case #PB_EventType_LeftClick
              ;Do Something else
          EndSelect
      EndSelect
  EndSelect
ForEver
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
ClueLess
Enthusiast
Enthusiast
Posts: 360
Joined: Sun Jan 11, 2009 1:04 am

Re: New Problem

Post by ClueLess »

Fixed With Your Hrlp

Thak You
User avatar
Mindphazer
Enthusiast
Enthusiast
Posts: 456
Joined: Mon Sep 10, 2012 10:41 am
Location: Savoie

Re: New Problem

Post by Mindphazer »

ClueLess wrote: Sat Sep 21, 2024 8:49 pm @Mindphazer
Not the same problem
Really ? Here is your faulty code tonight

Code: Select all

Event = WaitWindowEvent()
If event = #PB_Event_Gadget
  If EventGadget() = #But_Artigo_Delete
    DeleteArtigo()
  ElseIf EventGadget() = #But_Cancel_Artigo_List
    Event = #PB_Event_CloseWindow  
  ElseIf EventGadget() = #But_artigo_Select
;      LimparFormArtigo() 
  EndIf
EndIf

 Repeat 
  Until Event = #PB_Event_CloseWindow
And this is your code two days ago :

Code: Select all

Select WindowEvent()
  Case #PB_Event_Gadget
    Select EventGadget()
      Case #But_Guardar_Artigo
        GuardarArtigo()
    EndSelect
EndSelect

Repeat
  event = WaitWindowEvent()
Until event = #PB_Event_CloseWindow
You do not process events inside the loop in both cases.
MacBook Pro 16" M4 Pro - 24 Gb - MacOS 15.4.1 - Iphone 15 Pro Max - iPad at home
...and unfortunately... Windows at work...
Post Reply