Page 1 of 1

New Problem

Posted: Sat Sep 21, 2024 8:27 pm
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

Re: New Problem

Posted: Sat Sep 21, 2024 8:35 pm
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


Re: New Problem

Posted: Sat Sep 21, 2024 8:36 pm
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".

Re: New Problem

Posted: Sat Sep 21, 2024 8:36 pm
by Mindphazer
Same error as in your post 2 days ago
Don't you read the answers we made ?????

Re: New Problem

Posted: Sat Sep 21, 2024 8:49 pm
by ClueLess
@Mindphazer
Not the same problem

Re: New Problem

Posted: Sat Sep 21, 2024 8:51 pm
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

Re: New Problem

Posted: Sat Sep 21, 2024 9:01 pm
by ClueLess
Fixed With Your Hrlp

Thak You

Re: New Problem

Posted: Sat Sep 21, 2024 10:32 pm
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.