English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 18 February 2021, 11:28   #1
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
GTListView

Hi All,

Is GTListView an alternative to trying to code a scrollbar in a new window?

If so, would anyone have a basic working example of a simple GTListView attached to a new window they could share please? I tried to write one from an example I found online but it wouldn't compile for some reason unfortunately.

Thanks in advance!
JJ__ is offline  
Old 18 February 2021, 13:27   #2
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Here's a working example, but bear in mind that you need to do a GTChangeList command to detach and reattach the list to the listview whenever you change the list, otherwise bad things will happen. Also, this is AmiBlitz3 code, if you're compiling under Blitz 2.1, I think you need to set a finite limit on the size of a List array, which limits how many entries you can display.

Code:
WbToScreen 0

NEWTYPE .listitem
  dummy.w
  itemname.s
End NEWTYPE

Dim List MyListItems.listitem(0)

For i.w = 1 To 50
  If AddItem(MyListItems())
    MyListItems()\itemname = "Entry " + Str$(i)
  End If
Next i

GTNewLookProp On ; Gives the nicer looking sliders

GTTags #GTLV_ShowSelected, 0 ; Leaves the selected bar on the last clicked entry

GTListView 0, 0, 10, 10, 150, 150, "List Options", #PLACETEXT_BELOW, MyListItems()


Window 0, 200, 200, 200, 200, #WFLG_DRAGBAR|#WFLG_CLOSEGADGET|#WFLG_DEPTHGADGET, "Test", 0, 1

AttachGTList 0, 0

DefaultOutput

Repeat
  ev.l = WaitEvent
  If ev
    NPrint "Event: ", Hex$(ev)
    If ev = #IDCMP_GADGETUP
      If GadgetHit = 0
        NPrint "Listview hit: ", EventCode
      End If
    End If
  End If
Until ev = #IDCMP_CLOSEWINDOW

End
Where did you find the example you tried? Curious what might be wrong with it...
Daedalus is offline  
Old 18 February 2021, 15:05   #3
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
Where did you find the example you tried? Curious what might be wrong with it...[/QUOTE]

Thanks for this code and I will give it a whirl later! The program I typed out came from https://amigacoding.com in the GadTools section there is some example code which I tried but it came up with a 'Constant Error' or 'Constant Mismatch' error or something like that.

Probably me typing it out wrong, but I couldn't get it to work unfortunately.

Cheers!
JJ__ is offline  
Old 18 February 2021, 15:19   #4
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Ha, that's my code on AmigaCoding.com, probably from the same test code as I pasted there. I think I see the problem though - the example on the site is missing the list variable type. Sorry about that, I've fixed it now
Daedalus is offline  
Old 18 February 2021, 21:17   #5
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
Quote:
Originally Posted by Daedalus View Post
Ha, that's my code on AmigaCoding.com, probably from the same test code as I pasted there. I think I see the problem though - the example on the site is missing the list variable type. Sorry about that, I've fixed it now
no worries and thanks for fixing the code.
JJ__ is offline  
Old 21 February 2021, 11:50   #6
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
[QUOTE=Daedalus;1463288]Here's a working example, but bear in mind that you need to do a GTChangeList command to detach and reattach the list to the listview whenever you change the list, otherwise bad things will happen. Also, this is AmiBlitz3 code, if you're compiling under Blitz 2.1, I think you need to set a finite limit on the size of a List array, which limits how many entries you can display.

Code:
WbToScreen 0

NEWTYPE .listitem
  dummy.w
  itemname.s
End NEWTYPE

Dim List MyListItems.listitem(0)

For i.w = 1 To 50
  If AddItem(MyListItems())
    MyListItems()\itemname = "Entry " + Str$(i)
  End If
Next i

GTNewLookProp On ; Gives the nicer looking sliders

GTTags #GTLV_ShowSelected, 0 ; Leaves the selected bar on the last clicked entry

GTListView 0, 0, 10, 10, 150, 150, "List Options", #PLACETEXT_BELOW, MyListItems()


Window 0, 200, 200, 200, 200, #WFLG_DRAGBAR|#WFLG_CLOSEGADGET|#WFLG_DEPTHGADGET, "Test", 0, 1

AttachGTList 0, 0

DefaultOutput

Repeat
  ev.l = WaitEvent
  If ev
    NPrint "Event: ", Hex$(ev)
    If ev = #IDCMP_GADGETUP
      If GadgetHit = 0
        NPrint "Listview hit: ", EventCode
      End If
    End If
  End If
Until ev = #IDCMP_CLOSEWINDOW

End
Hi Daedalus,

I've just put this code into BB 2.1 which I've got and it's come up with an error against the line ... GTNewLookProp On

It says "Garbage at end of Line" as it doesn't recognise the command GTNewLookProp so it thinks the command is On. I've had a look at the BB manual and I can't see that instruction as part of the list unfortunately.

If I put a semicolon in front of the command it then doesn't like the line GTTags #GTLV_ShowSelected, 0 The error message for that one is "Constant Not Found".

Any ideas mate?

Thanks!
JJ__ is offline  
Old 21 February 2021, 18:13   #7
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Okay, for Blitz 2.1, you'll need to use a different value to 0 for the Dim statement - large enough to contain the maximum number of items you might want to show in the list. And you must make sure you don't exceed this number.

The constant not found error is due to not having the amigalibs.res file entered in the compiler settings. You need this to use any OS flags and structures. Add

Blitzlibs:amigalibs.res

to the resident files section of the Compiler settings/options.

The GTNewLookProp command isn't essential - you can probably achieve the same result using GTTags and the relevant values, but just comment it out for testing purposes. There are a couple of different versions of the GadToolsLib floating around - I suspect the command is simply missing from the one you have. I'll check it out though and see what's going on.
Daedalus is offline  
Old 23 February 2021, 21:27   #8
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
Quote:
Originally Posted by Daedalus View Post
Okay, for Blitz 2.1, you'll need to use a different value to 0 for the Dim statement - large enough to contain the maximum number of items you might want to show in the list. And you must make sure you don't exceed this number.

The constant not found error is due to not having the amigalibs.res file entered in the compiler settings. You need this to use any OS flags and structures. Add

Blitzlibs:amigalibs.res

to the resident files section of the Compiler settings/options.

The GTNewLookProp command isn't essential - you can probably achieve the same result using GTTags and the relevant values, but just comment it out for testing purposes. There are a couple of different versions of the GadToolsLib floating around - I suspect the command is simply missing from the one you have. I'll check it out though and see what's going on.
Hi Daedalus,

ok, I think we are getting there!

So I've created an array with 200 in it and I've added the amigalibs.res to the compiler settings and I've commented out the GTNewLookProp command to bypass it, but when I compile the program I now get a syntax error against line NPrint "Listview hit: ", EventCode

Any ideas please?

Thank you!
JJ__ is offline  
Old 23 February 2021, 23:57   #9
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Hmmm, that should simply print the code of the last event. Does it recognise and highlight the EventCode command/function? If so, try just

NPrint EventCode

or even

ec.l = EventCode
NPrint ec

A syntax error is usually some pretty obvious typo though - are you sure you have the correct quotes and comma used?
Daedalus is offline  
Old 24 February 2021, 22:00   #10
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
I think I must have typed something wrong last night with the NPrint EventCode line as it's not an issue today. Sorry ... not sure what happened there.

On another note, I now get "Cannot open window" with the line ...
Window 0, 200, 200, 200, 200, #WFLG_DRAGBAR|#WFLG_CLOSEGADGET|#WFLG_DEPTHGADGET, "Test", 0, 1

I tried changing the tags to $1|$2|$4|$8 just to see if that would make a difference but it didn't sadly and I still get the same error.

JJ__ is offline  
Old 25 February 2021, 14:04   #11
Daedalus
Registered User
 
Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 6,334
Hmmm, is the window too big for your screenmode maybe? Try setting the X and Y coordinates to 0 instead:
Window 0, 0, 0, 200, 200, #WFLG_DRAGBAR|#WFLG_CLOSEGADGET|#WFLG_DEPTHGADGET, "Test", 0, 1
Daedalus is offline  
Old 25 February 2021, 20:32   #12
JJ__
Registered User
 
Join Date: Jan 2021
Location: UK
Posts: 53
I got it working wohoo! :-)

Thanks Daedalus. So the only bit I couldn't get working was the line GTNewLookProp On.

Other than that it runs fine.
JJ__ is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 14:56.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09867 seconds with 14 queries