Announcement

Collapse
No announcement yet.

CopyRect() and Win2000..

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

  • CopyRect() and Win2000..

    I had some problems with a code snippet in Win2000, traced it down
    to a CopyRect(a, b) call, changed it to "a.nLeft = b.nLeft", etc,
    instead and the problem disappeared.

    Strange, IMHO. The code worked fine as it was in Win98. Has anyone
    else stumbled on this one before, or am I just imaginating things?


    ------------------

  • #2
    I always use LSET A=B rather than the overhead of the API call, so I've never needed to use that API.

    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Aha, thanks for the tip. Didn't know this. Help file says about LSET,
      "Left align a string within the space of another string." A RECT
      structure isn't exactly a string, but I just tested and it works
      fine. Maybe should be added to the help file..


      ------------------

      Comment


      • #4
        Won't "Rect1 = Rect2" work if they are both RECT structures?

        -- Eric

        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>
        "Not my circus, not my monkeys."

        Comment


        • #5
          Yes you can omit the LSET, but only if the argument is an identical UDT structure as the structure variable on the left of the assignment.

          LSET is commonly used to assign string data into UDTs & Unions. It is therefore a very handy technique for copying "non-compatible" structure, string, or string expression data into a UDT/Union. In such cases, LSET (or RSET) is manditory or the compiler will flag the line as using incompatible data types.

          In the UDT example above, adding LSET to the line will ensure the allocation still works if B is not a RECT structure. Further, it will not add any additional/unnecessary overhead to your app whether you include LSET or not.

          And yes, additional notes about this topic are scheduled to be added to the next update to the doc's.

          BTW, Borje, when the API failed, what did GetLastError() report? Any ideas why the API failed? Curious minds inquire...

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


          • #6
            No error was produced. It simply didn't copy the values, so the 2:nd
            RECT came through empty. Quite easily spotted, but very strange,
            since it worked fine in Win98.

            Not entirely sure CopyRect was the culprit either, because the code
            was a bit old and contained a few GDI mistakes( I'm learning..),
            which I fixed at the same time. That's why I asked if someone else
            ever had seen this problem before, or if i was just imaginating
            things..


            ------------------

            Comment


            • #7
              If CopyRect() fails, it should return zero, and then you can check GetLastError() for the extended error code.

              Did you check the return value by any chance?

              I did a quick test with PB/CC under Win2K and the RECT structures were copied sucessfully for me...
              Code:
              #include "win32api.inc"
              function pbmain
                  dim a as rect, b as rect
                  b.nleft = 10
                  b.ntop = 20
                  b.nright = 30
                  b.nbottom = 40
                  print CopyRect(a,b)
                  print a.nleft
                  print a.ntop
                  print a.nright
                  print a.nbottom
                  waitkey$
              end function

              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                Not in original code, no. When problem was found, I did, but no
                error was produced. Simply "copied" zero values.

                Since you have tested, I begin to think the problem originated
                elsewhere. Could have been one of those dreadful "hanging errors"
                that sometimes is caused by A and pops up at B. I did fix a few
                other things at the same time, so..

                In any events. I have learned something new. LSET or A = B must be
                both leaner and faster, so something good has come out of it.
                It always does, doesn't it?


                ------------------

                Comment

                Working...
                X