Thank you for your rapid and excellent response.
I wrote a small test based on your code.
It works fine.

Code: Select all
Debug ListEx::CountItems(#Books_lst_results)
ListEx::ClearItems(#Books_lst_results)
Debug ListEx::CountItems(#Books_lst_results)
If DatabaseQuery(#db, "SELECT * FROM Books WHERE " + query)
While NextDatabaseRow(#db)
ListEx::AddItem(#Books_lst_results, -1, GetDatabaseString(#db,0) + #LF$ + GetDatabaseString(#db,1) +
#LF$ + GetDatabaseString(#db,2) + #LF$ + GetDatabaseString(#db,3) + #LF$ + GetDatabaseString(#db,4) +
#LF$ + GetDatabaseString(#db,5) + #LF$ + GetDatabaseString(#db,6))
Wend
FinishDatabaseQuery(#db)
Debug ListEx::CountItems(#Books_lst_results)
If ListEx::CountItems(#Books_lst_results) = 0
ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results")
EndIf
EndIf
Code: Select all
If ListEx::CountItems(#Books_lst_results) = 0
ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results")
EndIf
I think he's saying when he calls this section of code again, all Debug lines return 1 yet Debug in line 3 should always return 0 since he clears it right before in line 2.infratec wrote:![]()
![]()
So you add 1 entry and you always get 1 as count result.Code: Select all
If ListEx::CountItems(#Books_lst_results) = 0 ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results") EndIf
Insert the code into the module, then you can find out where the 1 comes from.doctorized wrote:The above code is inside a procedure which is called many times. The first time the procedure runs ok, the debugs return all zero but every other time, debugs return 1 even if ClearItem() is called. All other times I should get 1, 0, 0 because of ClearItems(). Item "no results" is cleared, I do not see it any more but CountItems() is stuck to 1. DB is empty for now, that's why there are no results no matter what we search.
Code: Select all
Declare DebugList(GNum.i)
Procedure DebugList(GNum.i)
If FindMapElement(ListEx(), Str(GNum))
Debug "----- Debug -----"
ForEach ListEx()\Rows()
Debug ">>> Row " + Str(ListIndex(ListEx()\Rows()))
ForEach ListEx()\Rows()\Column()
Debug "Column " + MapKey(ListEx()\Rows()\Column()) + ": " + ListEx()\Rows()\Column()\Value
Next
Next
Debug "-----------------"
EndIf
EndProcedure
I ran the code and returns this:Thorsten1867 wrote:Insert the code into the module, then you can find out where the 1 comes from.
Code: Select all
Declare DebugList(GNum.i) Procedure DebugList(GNum.i) ... EndProcedure
Code: Select all
****** procedure call ******
----- Debug -----
-----------------
0
----- Debug -----
-----------------
0
0
----- Debug -----
-----------------
****** procedure call ******
----- Debug -----
>>> Row 0
Column 0:
Column 1: No results
-----------------
1
----- Debug -----
-----------------
1
1
----- Debug -----
-----------------
Code: Select all
Debug "****** procedure call ******"
ListEx::DebugList(#Books_lst_results)
Debug ListEx::CountItems(#Books_lst_results)
ListEx::ClearItems(#Books_lst_results)
ListEx::DebugList(#Books_lst_results)
Debug ListEx::CountItems(#Books_lst_results)
If DatabaseQuery(#db, "SELECT * FROM Books WHERE " + query)
While NextDatabaseRow(#db)
ListEx::AddItem(#Books_lst_results, -1, GetDatabaseString(#db,0) + #LF$ + GetDatabaseString(#db,1) +
#LF$ + GetDatabaseString(#db,2) + #LF$ + GetDatabaseString(#db,3) + #LF$ + GetDatabaseString(#db,4) +
#LF$ + GetDatabaseString(#db,5) + #LF$ + GetDatabaseString(#db,6))
Wend
FinishDatabaseQuery(#db)
Debug ListEx::CountItems(#Books_lst_results)
ListEx::DebugList(#Books_lst_results)
If ListEx::CountItems(#Books_lst_results) = 0
ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results")
EndIf
EndIf
Code: Select all
XIncludeFile "ListExModule.pbi"
#List = 1
#Button = 2
Procedure Test()
Debug "****** procedure call ******"
Debug ListEx::CountItems(#List)
ListEx::ClearItems(#List)
Debug ListEx::CountItems(#List)
If ListEx::CountItems(#List) = 0
ListEx::AddItem(#List, 0, "" + #LF$ + "No results")
EndIf
EndProcedure
If OpenWindow(0, 100, 100, 300, 115, "Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#Button, 5, 90, 90, 20, "Procedure")
ListEx::Gadget(#List, 5, 5, 290, 80, "Column 1", 60, "col1", ListEx::#GridLines)
ListEx::AddColumn(#List, 1, "Column 2", 80, "col2")
ListEx::AddItem(#List, ListEx::#LastItem, "Test 1" + #LF$ + "Test 2")
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
If EventGadget() = #Button : Test() : EndIf
EndSelect
Until Event = #PB_Event_CloseWindow
CloseWindow(0)
EndIf
Something bad is going on but how can I find out what? I tried PurifierGranularity(1,1,1,1) but didn't help. I must start deleting code to see what is causing the problem.Thorsten1867 wrote:Can't reproduce the problem.
Code: Select all
PurifierGranularity(1,1,1,1)
XIncludeFile "ListExModule.pbi"
Global FontName.s = "Arial"
Global FontSize.a = 11
Enumeration
#Font_Custom
#Font_Custom_B
#MainWindow
#Books_cont
#Books_pnl_add
#Books_cont_add
#Books_pnl_search
#Books_Search_txt_id
#Books_Search_str_id
#Books_cont_search
#Books_frm_search_criteria
#Books_frm_search_results
#Books_btn_search
#Books_lst_results
EndEnumeration
Procedure SearchBooks()
Debug "****** procedure call ******"
ListEx::DebugList(#Books_lst_results)
Debug ListEx::CountItems(#Books_lst_results)
ListEx::ClearItems(#Books_lst_results)
ListEx::DebugList(#Books_lst_results)
Debug ListEx::CountItems(#Books_lst_results)
ListEx::DebugList(#Books_lst_results)
If ListEx::CountItems(#Books_lst_results) = 0
ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results")
EndIf
EndProcedure
LoadFont(#Font_Custom, FontName, FontSize)
LoadFont(#Font_Custom_B, FontName, FontSize, #PB_Font_Bold)
If OpenWindow(#MainWindow, 0, 0, 800, 800, "Library", #PB_Window_ScreenCentered|#PB_Window_MinimizeGadget)
;-Books items
ContainerGadget(#Books_cont,-1,122,WindowWidth(#MainWindow)+2,WindowHeight(#MainWindow)-119,#PB_Container_Single)
ButtonGadget(#Books_pnl_search,10,10,200,35,"Find book")
ContainerGadget(#Books_cont_search,0,45,WindowWidth(#MainWindow),WindowHeight(#MainWindow)-168,#PB_Container_Flat)
FrameGadget(#Books_frm_search_criteria,10,1,200,WindowHeight(#MainWindow)-180,"Search criteria")
TextGadget(#Books_search_txt_id,20,80,180,20,"Book ID:")
StringGadget(#Books_Search_str_id,20,100,180,25,"")
ButtonGadget(#Books_btn_search,20,400,180,35,"Find book")
FrameGadget(#Books_frm_search_results,220,1,570,WindowHeight(#MainWindow)-180,"Results")
ListEx::Gadget(#Books_lst_results,230,23,550,WindowHeight(#MainWindow)-210, "id", 80, "", ListEx::#GridLines)
ListEx::AddColumn(#Books_lst_results,1,"title",230)
ListEx::AddColumn(#Books_lst_results,2,"writer",140)
ListEx::AddColumn(#Books_lst_results,3,"publisher",140)
ListEx::AddColumn(#Books_lst_results,4,"year",100)
ListEx::AddColumn(#Books_lst_results,5,"copies",100)
ListEx::AddColumn(#Books_lst_results,6,"ISBN",100)
ListEx::DisableReDraw(#Books_lst_results, #True)
ListEx::SetHeaderAttribute(#Books_lst_results, ListEx::#Align, ListEx::#Center)
ListEx::SetFont(#Books_lst_results, FontID(#Font_Custom))
ListEx::SetFont(#Books_lst_results, FontID(#Font_Custom_B), ListEx::#HeaderFont)
ListEx::DisableReDraw(#Books_lst_results, #False)
ListEx::SetRowsHeight(#Books_lst_results, 22)
ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
ListEx::SetColorTheme(#Books_lst_results, ListColorTheme)
CloseGadgetList()
Repeat
Select (WaitWindowEvent())
Case #PB_Event_CloseWindow
Done = #True
;-ButtonEx events
Case #PB_Event_Gadget
evnt = EventGadget()
Select evnt
Case #Books_btn_search
SearchBooks()
EndSelect
EndSelect
Until Done
EndIf
Code: Select all
ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
I use a version downloaded this August. I didn't check for new version since then.Paul wrote:@doctorized
This line gives error...
[13:27:02] [COMPILER] Line 65: Constant Not found: #ResizeHeight.
I downloaded the latest version of ListExModule.pbi And cannot find the constant #ResizeHeight anywhere.Code: Select all
ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
Curious where you get this constant. Maybe you are using a version that is causing you problems?
This must be quite an old version of ListEx.Paul wrote:@doctorizedCode: Select all
ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
Code: Select all
ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#Height)
Code: Select all
****** procedure call ******
----- Debug -----
-----------------
0
----- Debug -----
-----------------
0
----- Debug -----
-----------------
****** procedure call ******
----- Debug -----
>>> Row 0
Column 0:
Column 1: No results
-----------------
1
----- Debug -----
-----------------
0
----- Debug -----
-----------------
Code: Select all
ListEx::Gadget(#Students_lst_add_all,20,140,WindowWidth(#MainWindow)-40,WindowHeight(#MainWindow)-360, "id", 30, "", ListEx::#GridLines|ListEx::#AutoResize)
Code: Select all
ListEx::SetAutoResizeFlags(#Students_lst_add_all, ListEx::#Width)
Try version from 10.11.2019.doctorized wrote: ...but auto resizing columns' width is not working.