SetGadgetItemText, AddGadgetItem and chr(10)

Just starting out? Need help? Post your questions and find answers here.
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 127
Joined: Fri May 02, 2003 12:19 pm
Location: France

SetGadgetItemText, AddGadgetItem and chr(10)

Post by CONVERT »

Hello,

In the ListIconGadget() documentation, it is written:
  • "SetGadgetItemText(): Changes the current text of the specified item. (or column header, if item = -1). Like with AddGadgetItem(), it is possible to set the text for several columns at once, with the Chr(10) separator."
In PureBasic 5.42 LTS (Windows - x86), it seems that SetGadgetItemText() has not the same behavior as AddGadgetItem() regarding the Chr(10) separator.

It is shown in the example below, where I wonder if I wrote wrong code.
This code displays a table of 3 lines. When clicking on the "Modify line 2" button, the values in the line 2 change: A4 B4 C4, then A8 B8 C8 then A12 B12 C12, etc...

It works with the modify_line_alternative(1) procedure. It does not work with the modify_line(1) where SetGadgetItemText() is used in the same way as AddGadgetItem() written in Open_window().

You can choose modify_line_alternative(1) procedure or modify_line(1) procedure by setting a ";" just before.

Thanks for your help if I wrote wrong code.

Code: Select all

EnableExplicit

Enumeration
  #zero
  #window
  #list_icon_gadget
  #button_gadget
EndEnumeration

Procedure.s load_line(Pline.i)
  Define wlig$
  wlig$ = "A"+Str(Pline) + #LF$ + "B"+Str(Pline) + #LF$ + "C"+Str(Pline)
  ProcedureReturn wlig$
EndProcedure


Procedure Open_window()
  Define wline.i, wlig$
  
  If OpenWindow(#window,150,150,600,600,"Test SetGadgetItemText")
    ListIconGadget(#list_icon_gadget, 10, 10, 310, 100, "Column 1", 100)
      AddGadgetColumn(#list_icon_gadget, 1, "Column 2", 100)
      AddGadgetColumn(#list_icon_gadget, 2, "Column 3", 100)
      For wline = 0 To 2
        wlig$ = load_line(wline)
        AddGadgetItem(#list_icon_gadget,wline,wlig$)
      Next
      
      ButtonGadget(#button_gadget,400,10,150,30,"Modify line 2")
      
  EndIf
EndProcedure

Procedure modify_line(Pline.i)
  Define wlig$
  Static Sline.i
  Sline + 4
  wlig$ = load_line(Sline)
  SetGadgetItemText(#list_icon_gadget,Pline,wlig$)  
EndProcedure

Procedure modify_line_alternative(Pline.i)
  Define wlig$
  Static Sline.i
  Sline + 4
  wlig$ = load_line(Sline)
  SetGadgetItemText(#list_icon_gadget,Pline,"A"+Str(Sline),0)  
  SetGadgetItemText(#list_icon_gadget,Pline,"B"+Str(Sline),1)  
  SetGadgetItemText(#list_icon_gadget,Pline,"C"+Str(Sline),2)  
EndProcedure

Procedure ctl_window ()
  Define wEvent.i, wEvent_gadget.i
  
  Repeat
    wEvent = WaitWindowEvent()
    Select wEvent
      Case #PB_Event_Gadget
        wEvent_gadget = EventGadget()
        Select wEvent_gadget
          Case #button_gadget
            modify_line(1)
            ; modify_line_alternative(1)
        EndSelect
        
    EndSelect
  Until wEvent = #PB_Event_CloseWindow
  
EndProcedure

;- BEGIN

If #LF$ <> Chr(10)  ; just to be sure...
  End
EndIf

open_window()
ctl_window()

End
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4661
Joined: Sun Apr 12, 2009 6:27 am

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by RASHAD »

Hi
with ListIcon SetGadgetItemText() you must specify the row and the column

Code: Select all

Procedure modify_line(Pline.i)
  Define wlig$,k.i,a$
  Static Sline.i
  Sline + 4
  wlig$ = load_line(Sline)  
  For k = 1 To 3
    a$ = StringField(wlig$, k, #LF$)
    SetGadgetItemText(#list_icon_gadget,Pline,a$,k-1)
  Next
EndProcedure
Egypt my love
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 127
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by CONVERT »

Thanks Rashad,

Yes, I wrote this turn around code. In this case, the documentation has to be modified.

And until PB 5.41 LTS, it worked.
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4661
Joined: Sun Apr 12, 2009 6:27 am

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by RASHAD »

Yes you are right :)
Just installed 5.41 again (did not notice that before)
Sorry mate
Egypt my love
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 127
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by CONVERT »

Thanks for the confirmation, Rashad. Great!
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
Dude
Addict
Addict
Posts: 1907
Joined: Mon Feb 16, 2015 2:49 pm

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by Dude »

User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 127
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by CONVERT »

Thanks for the information, Dude.

I looked for SetGadgetItemText in the forums, but I did not find your post.

My problem is similar, but not quite the same.
Fred fixed your bug on January 29, 2016, and the 5.42 LTS was published on March 1st, 2016.
My problem does not exist with 5.41 LTS. So, it seems it appeared when fixing your bug :wink:

Anyway, it's easy to turn around it. I added a routine for the modification cases in my program, using the column number instead of #LF$.
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
Olby
Enthusiast
Enthusiast
Posts: 461
Joined: Mon Jan 12, 2009 10:33 am
Contact:

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by Olby »

It's a bug and has only appeared recently. Just upgraded to 5.42 LTS and compiled a program which was working just fine in 5.41 LTS. Now I am also getting the same issue.

The documentation for ListIconGadget() states:

- SetGadgetItemText(): Changes the current text of the specified item. (or column header, if item = -1). Like with AddGadgetItem(), it is possible to set the text for several columns at once, with the Chr(10) separator.
Intel Core i7 Quad 2.3 Ghz, 8GB RAM, GeForce GT 630M 2GB, Windows 10 (x64)
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 127
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by CONVERT »

I agree with you, Olby.
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
User avatar
CONVERT
Enthusiast
Enthusiast
Posts: 127
Joined: Fri May 02, 2003 12:19 pm
Location: France

Re: SetGadgetItemText, AddGadgetItem and chr(10)

Post by CONVERT »

I posted this subject in the "Bug Reports ‹ Bugs - Windows" forum.

http://www.purebasic.fr/english/viewtop ... =4&t=65358

Jean.
PureBasic 6.01 LTS 64 bit | Windows 10 Pro x64 | Intel(R) Core(TM) i7-8700 CPU @ 3.20Ghz 16 GB RAM, SSD 500 GB, PC locally assembled
Post Reply