Author Topic: Calling functions with array members (brackets or parenthesis)?  (Read 1205 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Hero Member
  • *****
  • Posts: 977
Hi Charles,

this little example is derived from examples/wingui/controls.o2bas. Due to my nicotine addiction it took 7 days to complete a code which would normally have been done in half an hour. But I see light at the end of the tunnel.

For creating the controls I applied variables in an array using expressions in square brackets. This works ok with the exception when calling a WinApi function like in case WM_SIZE, line 70 and line 71:

'MoveWindow (hchw[x + y*dimW], - will fail
MoveWindow (hchw(x + y*dimW),  - will work

Is it mandatory to apply parentheses when calling functions with array members? I do not know at the moment how this is treated with other languages.

Roland

Code: [Select]
$ filename "BtnCtrls.exe"
'uses RTL32
'uses RTL64

$ EscapeKeyEnd

uses WinUtil


int cx=60, cy=50
MainWindow 10*cx+8, 5*cy+40, WS_OVERLAPPEDWINDOW

 
% dimW 10
% dimH  5


function WndProc(sys hwnd, uint uMsg, sys wParam, lParam) as sys callback
'================================================================
indexbase 0

static sys hchw[0x200]
static int id_flag[0x200]
sys id
int x,y
 
 
select uMsg
 
  case WM_CREATE

     SetWindowText hwnd,"Controls"

     id = 0x100

     for y = 0 to < dimH
        for x = 0 to < dimW
           id ++         
           hchw[x + y*dimW] = CreateWindowEx(
                              0,
                              "button", str(id),
                              WS_CHILD | BS_TEXT | BS_PUSHBUTTON | WS_VISIBLE,
                              'x*cx,y*cy,cx,cy,
                              0,0,0,0,
                              hwnd, id,
                              inst, null)
        next x
     next y                               
       
  case WM_COMMAND
     id = loword (wparam)
     
     if id>0x100 and id<0x200 then
       SetWindowText hWnd, "PushButton: " str id
       id_flag[id-0x101] = not id_flag[id-0x101]
       if id_flag[id-0x101] then
         SetWindowText hchw[id-0x101], hex(id)+"h"
       else
         SetWindowText hchw[id-0x101], str(id)
       end if                         
       SetFocus hwnd
     end if

  case WM_SIZE   // main window changed size 
     cx = loword (lParam) / dimW
     cy = hiword (lParam) / dimH
         
     for y = 0 to < dimH
        for x = 0 to < dimW
           'MoveWindow (hchw[x + y*dimW],
           MoveWindow (hchw(x + y*dimW),
                       x * cx, y * cy,
                       cx, cy, true)
        next x
     next y                     

  case WM_DESTROY
     PostQuitMessage 0

  case else
     return DefWindowProc(hwnd, uMsg, wParam, lParam)
  end select
end function

Aurel

  • Guest
Re: Calling functions with array members (brackets or parenthesis)?
« Reply #1 on: April 09, 2020, 06:21:21 am »
Arnold
it work with square brackets but is moved left , probably because u use hex notation 0x200 which is
EX_CLIENTEDGE constant...like border.

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: Calling functions with array members (brackets or parenthesis)?
« Reply #2 on: April 09, 2020, 09:22:55 am »
Hi Roland,

I checked the o2 source code and found that operator precedence is not applied inside square brackets, so I will fix this. ( the compiler implements operator precedence by inserting bracket pairs into an expression so that operations are applied in the desired order).

Arnold

  • Hero Member
  • *****
  • Posts: 977
Re: Calling functions with array members (brackets or parenthesis)?
« Reply #3 on: April 10, 2020, 08:46:42 am »
Thank you Charles. After reading your explanations I found that I can apply this:

MoveWindow (hchw[x + (y*dimW)],
                        ....
which will work fine with version 0.2.8

Brian Alvarez

  • Hero Member
  • *****
  • Posts: 699
    • PluriBASIC
Re: Calling functions with array members (brackets or parenthesis)?
« Reply #4 on: April 19, 2020, 04:30:10 pm »
 This is interesting, is there an update by now? :)  Im checking....

Charles Pegge

  • Admin Support Member
  • *****
  • Posts: 4486
    • Oxygen Basic
Re: Calling functions with array members (brackets or parenthesis)?
« Reply #5 on: April 21, 2020, 10:39:06 am »
I have now posted OxygenBasicProgress.zip 0.2.9 :)