It is currently Thu Jun 20, 2013 12:40 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2
Author Message
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 1:00 pm 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 98
Location: Melbourne, AUS
Hi Luis,

Thanks again for your detailed reply and for spending so much time on my query.

Firstly though, I have read the manual, but like most software manuals this is written for users who understand the language.

I have not used a "Windows" language before and so found it very difficault to understand the concepts.

Luckilly I discovered the Pure Basic book by Gary Willoughby.

So I am now at the experimenting stage.

That said, I still don't have a good "feel" for the language and so I can't spot errors that would be simple for experienced users.

The problem with the *ptr/s mentioned in my earlier post is a good example.

I had copied your code example, but in my code I had defined the *ptr.string in the code for adding values to the list, whereas it appears that it has to be in the code to return the values from the list.

When I don't define it in the code to return the values, I get the error mentioned in my post about the variable *ptr not having a structure. Note that the error message doesn't say how to correct this.

I read about pointers in the manual and I didn't seem to find anywhere the reasons as to why you might use them!!

Anyway, once I had the define statement in the correct location my application worked except for one last issue.

I cannot get the correct return value !!

Here is code to populate the list:
Code:
   ForEach lAvevaLauncherServers()
      ; Add values displayed in list
      If FindMapElement(lAvevaLauncherServers()\Data(), "displayname")
         If lAvevaLauncherServers()\Data("status") = "Y" Or (lAvevaLauncherServers()\Data("status") = "A" And bAdminUser = "1")
            AddGadgetItem(Gadget_Form1_ListView8,-1,lAvevaLauncherServers()\Data("displayname"))
            Debug lAvevaLauncherServers()\Data("displayname")
            Debug lAvevaLauncherServers()\Data("shortname")
            *ptr = FindMapElement(lAvevaLauncherServers()\Data(), "shortname") ; address of the data     
            Debug *ptr
            SetGadgetItemData(Gadget_Form1_ListView8,-1, *ptr) ; store it           
         EndIf   
      EndIf


Here is the code to return the list value:

Code:
            Select EventType()
                  Case #PB_EventType_LeftDoubleClick
                  Default
                     Item = GetGadgetState(Gadget_Form1_ListView8)
                     Debug Item
                     *ptr = GetGadgetItemData(Gadget_Form1_ListView8,Item) ; get it
                     Debug *ptr
                     Debug *ptr\s
            EndSelect


Here is the debug output:


; Populate the List
: all seems ok - new *ptr values for each item
Melbourne Aveva Licence Server
MEL01
22560308
Dortmund Aveva Licence Server
DTM01
22562380
Dortmund Review Machine
DTM02
22562676
Bad Soden Aveva Licence Server
BDS01
22563268

; Try and get list value
; Select each item in the list
0
22563268
BDS01
1
22563268
BDS01
2
22563268
BDS01
3
22563268
BDS01


Note that even though the item returned is corrrect, GetGadgetItemData() always returns the same *ptr number !!

It looks as though the values stored in the code to populate the list are incorrect.

I'm sure that it is something simple as usual, but I'm afraid that I can't see it.

Thanks,

Neil


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 2:28 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2270
Location: Italy
You are using -1 in SetGadgetItemData(Gadget_Form1_ListView8,-1, *ptr).
Look at the help for SetGadgetItemData().
Is it -1 mentioned as a valid value as it is in AddGadgetItem() ?

help for AddGadgetItem() wrote:
Specifies the item index where the new item should be inserted. To add the item at the start, use an index of 0. To add this item to the end of the current item list, use a value of -1


-1 is a "special value", to be used instead of the actual item number when you want to add the new item at the last position.

Let's see the description of the item parameter for SetGadgetItemData().

help for SetGadgetItemData() wrote:
Item Specifies the item to use. The first item in the gadget has index 0.


So you just have to use the correct index for the item you are updating. You could simply use a counter instead of -1 for AddGadgetItem() and use the same counter for both AddGadgetItem() and SetGadgetItemData(), or use GetGadgetState() to retrieve it.

_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 2:58 pm 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 98
Location: Melbourne, AUS
Hey that's got it - thankyou !!

That's the method I would have used in the language I am familiar with.

I assumed the "-1" parameter would work the same for both functions.


Sorry, but now another question.

Can I store more than one lot of alternative values in the list ?

Judging by the help manual it would appear not.

Thanks,

Neil


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 3:06 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2270
Location: Italy
Neil wrote:
I assumed the "-1" parameter would work the same for both functions.


Don't assume, check the manual :wink:

Neil wrote:
Can I store more than one lot of alternative values in the list ?

Judging by the help manual it would appear not.


What list ?

_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 3:27 pm 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 98
Location: Melbourne, AUS
1. mmm - do you know a reason why both functions don't work the same ?

I would have thought if one can automatically increment from 0, the other would too.



2. The list in the form I have been working with in previous posts.

Code:
            AddGadgetItem(Gadget_Form1_ListView8,-1,lAvevaLauncherServers()\Data("displayname"))
            *ptr = FindMapElement(lAvevaLauncherServers()\Data(), "shortname") ; address of the data     
            SetGadgetItemData(Gadget_Form1_ListView8,-1, *ptr) ; store it


i.e. can I store:

(lAvevaLauncherServers()\Data(), "some_other_data")

in the list on the form, or do I just have to just find any other values in the linked list itself ??

I would assume not, but I thought I'd ask.

Thanks,

Niel


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 3:53 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2270
Location: Italy
Neil wrote:
1. mmm - do you know a reason why both functions don't work the same ?


No, I don't know the reason. The -1 is a convenience, not a strict requirement to make that command useful. Probably fred felt adding many items sequentially to a gadget was a common occurrence and added the -1 "special value", but didn't feel the same for other similar commands who can be used sequentially or not.
Anyway it's documented, so it's the way it is.

Neil wrote:
i.e. can I store:

(lAvevaLauncherServers()\Data(), "some_other_data")

in the list on the form, or do I just have to just find any other values in the linked list itself ??


Do you mean if you can store more than a value in the data field used by SetGadgetItemData() ?
If that's what you asking: you can store A SINGLE NUMBER.

But this number can be an address to an unlimited big data structure (that's what the pointers are for...)

In your case, for example, probably I wouldn't have stored the pointer to a specific string (a map value) as it is now, but the pointer of the list item containing the map instead. That way you can extract any field contained in the map from the list item.

_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 4:33 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2270
Location: Italy
The SetGadgetItemData() approach is more versatile, but in your case probably you can do what you want without it and without using pointers, simply using SelectElement() on your linked list.

This is you have a 1:1 correspondence between the linked list and the combobox.

Code:

EnableExplicit

Structure TEST
 Map M$()
EndStructure

Global NewList L.TEST()

AddElement(L())
L()\M$("name") = "name a"
L()\M$("surname") = "surname a"
L()\M$("addr") = "addr a"

AddElement(L())
L()\M$("name") = "name b"
L()\M$("surname") = "surname b"
L()\M$("addr") = "addr b"
AddElement(L())
L()\M$("name") = "name c"
L()\M$("surname") = "surname c"
L()\M$("addr") = "addr c"


Enumeration
 #WIN_MAIN
 #COMBO
EndEnumeration


Procedure Main()
 Protected iEvent, i
 
 If OpenWindow(#WIN_MAIN, 10, 10, 300, 100, "Test Window", #PB_Window_SystemMenu)
 
    ComboBoxGadget(#COMBO, 10, 10, 200, 20)
    ResetList(L())   
   
    ForEach L()                       
        AddGadgetItem(#COMBO,-1,L()\M$("name"))
    Next
   
    Repeat
        iEvent = WaitWindowEvent()
       
        Select iEvent
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case 1
                        i = GetGadgetState(#COMBO)
                       
                        Debug "gadget item = " + Str(i)
                       
                        SelectElement(L(),i) ; select that element insided the list
                       
                        ; access to ANY element inside that list item (in this case all the fields in the map)
                        Debug "name = " +  L()\M$("name")                       
                        Debug "surname = " +  L()\M$("surname")                       
                        Debug "addr = " +  L()\M$("addr")     
                       
                        Debug ""                 
                EndSelect
        EndSelect       
    Until iEvent = #PB_Event_CloseWindow
   
 EndIf
 
EndProcedure


Main()


_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Sun Mar 11, 2012 4:46 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Aug 31, 2005 11:09 pm
Posts: 2270
Location: Italy
And if there is not a 1:1 correspondence you can still use SetItemGadgetData() and SelectElement() together, with no pointers.


Code:
EnableExplicit

Structure TEST
 Map M$()
EndStructure

Global NewList L.TEST()

AddElement(L())
L()\M$("name") = "name a"
L()\M$("surname") = "surname a"
L()\M$("addr") = "addr a"
AddElement(L())
L()\M$("name") = "name b"
L()\M$("surname") = "surname b"
L()\M$("addr") = "addr b"
AddElement(L())
L()\M$("name") = "X" ; this will be discarded
L()\M$("surname") = "X" ; this will be discarded
L()\M$("addr") = "X" ; this will be discarded
AddElement(L())
L()\M$("name") = "name c"
L()\M$("surname") = "surname c"
L()\M$("addr") = "addr c"


Enumeration
 #WIN_MAIN
 #COMBO
EndEnumeration


Procedure Main()
 Protected iEvent, i, iListItem
 
 If OpenWindow(#WIN_MAIN, 10, 10, 300, 100, "Test Window", #PB_Window_SystemMenu)
 
    ComboBoxGadget(#COMBO, 10, 10, 200, 20)
    ResetList(L())   
   
    ForEach L()   
        If L()\M$("name") <> "X" ; If this is a item you want to add to the list
            AddGadgetItem(#COMBO,-1, L()\M$("name"))           
            SetGadgetItemData(#COMBO, CountGadgetItems(#COMBO) - 1, iListItem) ; save the list element sequential number       
        EndIf       
        iListItem + 1
    Next
   
    Repeat
        iEvent = WaitWindowEvent()
       
        Select iEvent
            Case #PB_Event_Gadget
                Select EventGadget()
                    Case  #COMBO
                        i = GetGadgetState(#COMBO)
                       
                        Debug "gadget item = " + Str(i)
                        Debug "gadget item data = " + Str(GetGadgetItemData(#COMBO, i)) ; get the list element sequential number
                       
                        SelectElement(L(),GetGadgetItemData(#COMBO, i)) ; select that element insided the list
                       
                        ; access to ANY element inside that list item (in this case all the fields in the map)
                        Debug "name = " +  L()\M$("name")                       
                        Debug "surname = " +  L()\M$("surname")                       
                        Debug "addr = " +  L()\M$("addr")     
                       
                        Debug ""                 
                EndSelect
        EndSelect       
    Until iEvent = #PB_Event_CloseWindow
   
 EndIf
 
EndProcedure


Main()



But pointers are so nice ... :lol:

_________________
[ Home ] [ My PC ] [ New to PB ? ]


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Mon Mar 12, 2012 3:37 am 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 98
Location: Melbourne, AUS
Hi Luis,

Hey that is fantastic - just what I was after (yet again).

Thanks very much for the time you put into your replies - I hope I get a chance to help someone some day.

And you read my mind - I actually filter my lists as per your second example.



Just back to earlier dicussion about reading the manual - I did read the manual, but I didn't understand the significance of the fucntions or where they were used.

Now looking at your examples I check up any functions that are new to me in the help file and now I can see what they are getting at - it's all becoming clearer at last !!

Thanks again,

Neil


Just as a matter of interest - do you know who or how the topic gets [solved]/[resolved] added to it ?

I had a look through FAQ and posts and couldn't find anything.

It would be nice to close off all my queries.


Top
 Profile  
 
 Post subject: Re: Adding entries to a ListViewGadget using a linked list
PostPosted: Mon Mar 12, 2012 7:53 am 
Offline
Addict
Addict
User avatar

Joined: Mon Jul 25, 2005 3:51 pm
Posts: 2427
Location: Utah, USA
Neil wrote:
Just as a matter of interest - do you know who or how the topic gets [solved]/[resolved] added to it ?

I had a look through FAQ and posts and couldn't find anything.

It would be nice to close off all my queries.


@Neil: Just edit the original post and change the message subject when you do. The text for the subject is listed above the message body and it is editable as well.

_________________
Image


Top
 Profile  
 
 Post subject: Re: [solved] Adding entries to a ListView using a linked lis
PostPosted: Mon Mar 12, 2012 9:44 am 
Offline
User
User

Joined: Wed Feb 29, 2012 8:04 am
Posts: 98
Location: Melbourne, AUS
Great - thanks,

Neil


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 26 posts ]  Go to page Previous  1, 2

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 8 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye