[Modules] ListEx (all OS / DPI)

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: [Modules] ListEx (all OS / DPI)

Post by davido »

@Cyllceaux,
Thank you for your rapid and excellent response.

I wrote a small test based on your code.
It works fine. :D
DE AA EB
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [Modules] ListEx (all OS / DPI)

Post by doctorized »

In a project of mine I use ListEx and the following code:

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
when the code runs for the first time, all is fine, all three debugs return zero. Every following time all three debugs return 1. Am I missing something? Query is made dynamically, it is checked and it is fine.
infratec
Always Here
Always Here
Posts: 7578
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by infratec »

:?: :?: :?:

Code: Select all

If ListEx::CountItems(#Books_lst_results) = 0
      ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results")
   EndIf
So you add 1 entry and you always get 1 as count result.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Modules] ListEx (all OS / DPI)

Post by Paul »

infratec wrote::?: :?: :?:

Code: Select all

If ListEx::CountItems(#Books_lst_results) = 0
      ListEx::AddItem(#Books_lst_results, 0, "" + #LF$ + "No results")
   EndIf
So you add 1 entry and you always get 1 as count result.
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.
Image Image
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [Modules] ListEx (all OS / DPI)

Post by doctorized »

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.
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

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.
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)
    
    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
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [Modules] ListEx (all OS / DPI)

Post by doctorized »

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
I ran the code and returns this:

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 -----
-----------------
my code:

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
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

Can't reproduce the problem.

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 
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [Modules] ListEx (all OS / DPI)

Post by doctorized »

Thorsten1867 wrote:Can't reproduce the problem.
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.

EDIT

Here is a code that reproduces 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

EDIT 2
I tried your code. I always get 1. I use PB 5.71 b2, is this the problem?

EDIT 3
I noticed the last three days that my code delays 2-4 seconds to run when pressing F5 (it ran instantly before). I thought it had to do with the graphics and code added but now it doesn't seem logical for the above 85 lines that I posted.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: [Modules] ListEx (all OS / DPI)

Post by Paul »

@doctorized
This line gives error...
[13:27:02] [COMPILER] Line 65: Constant Not found: #ResizeHeight.

Code: Select all

ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
I downloaded the latest version of ListExModule.pbi And cannot find the constant #ResizeHeight anywhere.
Curious where you get this constant. Maybe you are using a version that is causing you problems?
Image Image
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [Modules] ListEx (all OS / DPI)

Post by doctorized »

Paul wrote:@doctorized
This line gives error...
[13:27:02] [COMPILER] Line 65: Constant Not found: #ResizeHeight.

Code: Select all

ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
I downloaded the latest version of ListExModule.pbi And cannot find the constant #ResizeHeight anywhere.
Curious where you get this constant. Maybe you are using a version that is causing you problems?
I use a version downloaded this August. I didn't check for new version since then.
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

Paul wrote:@doctorized

Code: Select all

ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#ResizeHeight)
This must be quite an old version of ListEx.

Code: Select all

ListEx::SetAutoResizeFlags(#Books_lst_results, ListEx::#Height)
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

@doctorized
Use the version from 4.11.2019, otherwise I have no comparison.

Result of your code:

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 -----
-----------------
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
User avatar
doctorized
Addict
Addict
Posts: 882
Joined: Fri Mar 27, 2009 9:41 am
Location: Athens, Greece

Re: [Modules] ListEx (all OS / DPI)

Post by doctorized »

Downloaded latest version. The problem disappeared. Thanx!!

Edit:
I say:

Code: Select all

ListEx::Gadget(#Students_lst_add_all,20,140,WindowWidth(#MainWindow)-40,WindowHeight(#MainWindow)-360, "id", 30, "", ListEx::#GridLines|ListEx::#AutoResize)
I also tried to add:

Code: Select all

ListEx::SetAutoResizeFlags(#Students_lst_add_all, ListEx::#Width)
but auto resizing columns' width is not working. Is there anything else needed?
User avatar
Thorsten1867
Addict
Addict
Posts: 1372
Joined: Wed Aug 24, 2005 4:02 pm
Location: Germany

Re: [Modules] ListEx (all OS / DPI)

Post by Thorsten1867 »

doctorized wrote: ...but auto resizing columns' width is not working.
Try version from 10.11.2019.
Translated with http://www.DeepL.com/Translator

Download of PureBasic - Modules
Download of PureBasic - Programs

[Windows 11 x64] [PB V5.7x]
Post Reply