xHarbour, array of structs?

  • Follow


Hi all,

I am still trying to learn the basics of a language. What is a
preferred way to create and fill an array of structs?

I first tried this, what feeled like the natural way to do it:

LOCAL point := (struct POINT)
LOCAL points := { point(10, 20), point(100, 100) }

....well, that didn't work.


I played around a bit more and this seemed to work:

LOCAL point := (struct POINT)
LOCAL points := { p IS point := {10, 20}, p IS point := { 100, 100 } }


Any better way to do it?
0
Reply jalih 3/25/2010 4:22:42 PM

On Mar 25, 9:22=A0am, jalih <jali.heino...@gmail.com> wrote:
> Hi all,
>
> I am still trying to learn the basics of a language. What is a
> preferred way to create and fill an array of structs?
>
> I first tried this, what feeled like the natural way to do it:
>
> LOCAL point :=3D (struct POINT)
> LOCAL points :=3D { point(10, 20), point(100, 100) }

In English, what are you trying to do?

> ...well, that didn't work.

This isn't C.  Structu5es are collections of possibly different data
types.  In xHarbour / Clipper, this is accomplished by using DBFs or
(more dangerously) Memory files.

> I played around a bit more and this seemed to work:
>
> LOCAL point :=3D (struct POINT)
> LOCAL points :=3D { p IS point :=3D {10, 20}, p IS point :=3D { 100, 100 =
} }
>
> Any better way to do it?

Arrays do not have a 0th item, they always start with a pointer #1.
Declaring variables LOCAL means they cannot be used in the evolution
of a macro, and are not visible outside the scope of teh routine that
declares them.

LOCAL point :=3D Array( 100, 100 )
.... for a 2D array, 100 x 100
LOCAL points :=3D { point(10, 20), point(100, 100) }
.... the array "points" is one dimensional, and points to *exactly the
same bit of memory* as the two addresses point(10, 20) and point(100,
100) do.  All array references are passed by reference, rather than by
value.
LOCAL points :=3D { ( point(10, 20)), ( point(100, 100)) }
.... probably will store their instananeous value instead.

David A. Smith
0
Reply dlzc 3/25/2010 7:49:36 PM


Could you please describe your ultimate objective? The question I have is do 
you really need a C level structures? I ask because xHarbour Arrays 
themselves can be used as structures (that is to hold collection of data of 
different or same type).

Ron

"jalih" <jali.heinonen@gmail.com> wrote in message 
news:f3b0fd5b-da21-46c4-b6af-890248fb5066@33g2000yqj.googlegroups.com...
> Hi all,
>
> I am still trying to learn the basics of a language. What is a
> preferred way to create and fill an array of structs?
>
> I first tried this, what feeled like the natural way to do it:
>
> LOCAL point := (struct POINT)
> LOCAL points := { point(10, 20), point(100, 100) }
>
> ...well, that didn't work.
>
>
> I played around a bit more and this seemed to work:
>
> LOCAL point := (struct POINT)
> LOCAL points := { p IS point := {10, 20}, p IS point := { 100, 100 } }
>
>
> Any better way to do it? 

0
Reply Ron 3/25/2010 9:34:52 PM

On 25 maalis, 23:34, "Ron Pinkas"
<Ron.Pinkas_remove_th...@xHarbour.com> wrote:
> Could you please describe your ultimate objective? The question I have is do
> you really need a C level structures? I ask because xHarbour Arrays
> themselves can be used as structures (that is to hold collection of data of
> different or same type).
>
> Ron
>

In a Win32 program, I would like to create an array of  points that I
could pass to PolyLine for drawing. What is a xHarbour way to do it?
0
Reply jalih 3/26/2010 9:09:41 AM

> In a Win32 program, I would like to create an array of  points that I
> could pass to PolyLine for drawing. What is a xHarbour way to do it?

That depends on which GUI platform you use.

Ron 
0
Reply Ron 3/26/2010 11:33:31 AM

On 26 maalis, 13:33, "Ron Pinkas"
<Ron.Pinkas_remove_th...@xHarbour.com> wrote:
> > In a Win32 program, I would like to create an array of  points that I
> > could pass to PolyLine for drawing. What is a xHarbour way to do it?
>
> That depends on which GUI platform you use.
>
> Ron

Just a basic Win32 app like the one below:



FUNCTION MainWndProc( hWnd, message, wParam, lParam )

   LOCAL ps, hDC

   LOCAL point := (struct POINT)
   LOCAL points := { p IS point := {10,20}, p IS point := {100,100}, p
IS point := {300, 50} }


   SWITCH message
      CASE WM_SETFOCUS
         EXIT

      CASE WM_PAINT
         hDC := BeginPaint( hWnd, @ps )
         Polyline(hDC, points, 3)
         DeleteDC(hDC)
         EndPaint( hWnd, ps )
         EXIT

      CASE WM_CREATE
         EXIT

      CASE WM_DESTROY
         PostQuitMessage( 0 )
         EXIT

      DEFAULT
         RETURN DefWindowProc( hWnd, message, wParam,
lParam )

   END

RETURN 0
0
Reply jalih 3/26/2010 2:09:40 PM

Just a dirty hack for legacy Windows apps:

CallDll( pPolyline, hDC, CalcPointString( @aL ), Int( len(aL) ) )

where:

function CalcPointString( aL )
   local i
   cPointString:=3D""
   for i:=3D1 to len( aL )
      cPointString:=3DcPointString + L2Bin( aL[i, 1] ) + L2Bin( aL[i,
2] )
   next
   pPointString:=3DHB_String2Pointer( cPointString )
return pPointString


Nowadays the OO classes do hide the low-level implementation details,
which might be different from one OS version to another, and I can't
support any attempt to add or combine the above code with the code
generated by an IDE.


Ella


> Just a basic Win32 app like the one below:
>
> FUNCTION MainWndProc( hWnd, message, wParam, lParam )
>
> =A0 =A0LOCAL ps, hDC
>
> =A0 =A0LOCAL point :=3D (struct POINT)
> =A0 =A0LOCAL points :=3D { p IS point :=3D {10,20}, p IS point :=3D {100,=
100}, p
> IS point :=3D {300, 50} }
>
> =A0 =A0SWITCH message
> =A0 =A0 =A0 CASE WM_SETFOCUS
> =A0 =A0 =A0 =A0 =A0EXIT
>
> =A0 =A0 =A0 CASE WM_PAINT
> =A0 =A0 =A0 =A0 =A0hDC :=3D BeginPaint( hWnd, @ps )
> =A0 =A0 =A0 =A0 =A0Polyline(hDC, points, 3)
> =A0 =A0 =A0 =A0 =A0DeleteDC(hDC)
> =A0 =A0 =A0 =A0 =A0EndPaint( hWnd, ps )
> =A0 =A0 =A0 =A0 =A0EXIT
>
> =A0 =A0 =A0 CASE WM_CREATE
> =A0 =A0 =A0 =A0 =A0EXIT
>
> =A0 =A0 =A0 CASE WM_DESTROY
> =A0 =A0 =A0 =A0 =A0PostQuitMessage( 0 )
> =A0 =A0 =A0 =A0 =A0EXIT
>
> =A0 =A0 =A0 DEFAULT
> =A0 =A0 =A0 =A0 =A0RETURN DefWindowProc( hWnd, message, wParam,
> lParam )
>
> =A0 =A0END
>
> RETURN 0

0
Reply Ella 3/26/2010 3:09:25 PM

Sorry, but which library do you use for Windows API access?

"jalih" <jali.heinonen@gmail.com> wrote in message 
news:ac720346-eea5-438b-9b18-351d279ea693@y17g2000yqd.googlegroups.com...
> On 26 maalis, 13:33, "Ron Pinkas"
> <Ron.Pinkas_remove_th...@xHarbour.com> wrote:
>> > In a Win32 program, I would like to create an array of  points that I
>> > could pass to PolyLine for drawing. What is a xHarbour way to do it?
>>
>> That depends on which GUI platform you use.
>>
>> Ron
>
> Just a basic Win32 app like the one below:
>
>
>
> FUNCTION MainWndProc( hWnd, message, wParam, lParam )
>
>   LOCAL ps, hDC
>
>   LOCAL point := (struct POINT)
>   LOCAL points := { p IS point := {10,20}, p IS point := {100,100}, p
> IS point := {300, 50} }
>
>
>   SWITCH message
>      CASE WM_SETFOCUS
>         EXIT
>
>      CASE WM_PAINT
>         hDC := BeginPaint( hWnd, @ps )
>         Polyline(hDC, points, 3)
>         DeleteDC(hDC)
>         EndPaint( hWnd, ps )
>         EXIT
>
>      CASE WM_CREATE
>         EXIT
>
>      CASE WM_DESTROY
>         PostQuitMessage( 0 )
>         EXIT
>
>      DEFAULT
>         RETURN DefWindowProc( hWnd, message, wParam,
> lParam )
>
>   END
>
> RETURN 0 

0
Reply Ron 3/27/2010 10:37:20 PM

7 Replies
237 Views

(page loaded in 0.108 seconds)

Similiar Articles:










7/7/2012 5:01:14 AM


Reply: