Announcement

Collapse

New Sub-Forum

In an effort to help make sure there are appropriate categories for topics of discussion that are happening, there is now a sub-forum for databases and database programming under Special Interest groups. Please direct questions, etc., about this topic to that sub-forum moving forward. Thank you.
See more
See less

List Box selection

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • List Box selection

    I have set up a multi selection list box and use the following code to find the lines selected:

    LOCAL I AS LONG
    LOCAL ENTRIES AS LONG
    DIM LINELIST(LINECOUNT) AS LOCAL LONG

    CONTROL SEND hDlg,%ID_LIST,%LB_GETSELITEMS,LINECOUNT,VARPTR(LINELIST()) TO ENTRIES

    If I select 3 Lines ENTRIES returns 3 but the array LINELIST() is empty.
    (LINECOUNT has the number of lines in the listbox).
    What is the problem?

  • #2
    Varptr(LineList()) gives you a pointer to the array descriptor, not the data. You should use ByVal Varptr(LineList(0))
    Regards,
    Peter

    Comment


    • #3
      Not directly on topic but...

      What a great example of potential memory corruption without a protection fault.

      And why 'no fault?' Because you OWN the memory used for the Array Descriptor.

      Let's say you 'change an array element' after setting the pointer using VARPTR(array())... you have just overwritten the array descriptor... no protection fault because you own that memory and have every right to overwrite it... but next time you ask the compiler to read an array element by subscript (e.g., X = Myarray(subscript)), don't be surprised if that doesn't result in something strange and wonderful!
      Michael Mattias
      Tal Systems Inc. (retired)
      Racine WI USA
      [email protected]
      http://www.talsystems.com

      Comment


      • #4
        List box problem

        Thank you Peter. I will try that.
        Sorry Michael, I'm just an old simpleton.
        Best regards both

        Comment


        • #5
          I brought this up only because we get a lot of postings here which go something like...
          My program gets a GPF at this line of code...
          Code:
             Z =  Array(I)
          .. and I is always in range and I don't get an error #9"
          To which the reply is often something like "your real problem may be memory corruption which occurred somewhere else in your program."

          This is an example of such "corruption somewhere else." And finding your problem in this case could turn into one of those "all day" things because you never look in the right place.

          It's really pretty easy to corrupt your memory, wouldn't you agree? And the logical conclusion is, "where your program aborts with a GPF is not necessarily where you made your error?"

          MCM
          Michael Mattias
          Tal Systems Inc. (retired)
          Racine WI USA
          [email protected]
          http://www.talsystems.com

          Comment


          • #6
            Errors

            Yes Michael, I found this only yesterday when I got a Printer fail but the actual fault was an earlier undimensioned array fault.
            Best wishes

            Comment


            • #7
              list box problem

              Sorry Peter but adding BYVAL produces a syntax error. VARPTR should pass by value anyway. But your note gave me a clue. I had not given an array subscript value so linelist(0) cured the problem. Why does't the compiler generate a fault I ask myself, and what value does it pass? No answer from the Powerbasic team?

              Comment


              • #8
                Peter gave you the correct answer 2 weeks ago. The very first response?

                Best--

                Bob Zale
                PowerBASIC Inc.

                Comment


                • #9
                  >Why does't the compiler generate a fault [?]

                  Because it's possible you really wanted to pass the address of the array descriptor.

                  Example: Single Function to process any array type (CC3/Win7+) 12-17-03

                  You command, compiler obeys.
                  Michael Mattias
                  Tal Systems Inc. (retired)
                  Racine WI USA
                  [email protected]
                  http://www.talsystems.com

                  Comment

                  Working...
                  X