It don't work

Here you can talk about anything related to BBC BASIC, not covered in another category
KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

It don't work

Post by KenDown »

Everyone - so it seems - is singing the praises of SDLIDE so I thought I would try using it. The program below is, I hope, as simple as it can get in starting up a program using a dialog box.

Code: Select all

      PROCinit
      END
      :
      DEFPROCinit
      INSTALL@lib$+"dlglib"

      maindlg%=FN_newdialog("New Display",320,240)
      showmain%=FN_showdialog(maindlg%,&FFFFFFFF80000000,&FFFFFFFF80000000)
      WAIT 200
      PROC_closedialog(showmain%)
"Bad use of structure in module C:\Program Files (x86)\BBC SDL\lib\dlglib"

And, almost as annoying, you don't get the error highlighted, as you do with BB4W. From the fact that the error only appeared when I put the line "showmain%=" in, I am assuming that is the offending line - but what have I done wrong?

Does anyone have any ideas?
Thanks.

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: It don't work

Post by DDRM »

Whoa! I understand your frustration, but please try to keep your tone courteous! :-)

Unfortunately given the limited documentation available (at least that I could find) I couldn't solve your problem in the time I was prepared to spend on it at the moment, but here's where I've got:
1) I note that the library says you must set the font and palette first, so I did that, but it doesn't solve the problem,
2) I set what looked like more sensible coordinates for displaying the new dialog. As with BB4W, dialogue box units do not match pixels/BBC plotting units, but that's OK.

With that, it at least displays the window before crashing...

I then pasted the FN_Showdialog out of the library, so it would use the local version, and I could play with it. Using breakpoints and print statements, I found where the issue is: it seems to crash around PROC_setptr (indicated below). I can't see why without really taking the routine to pieces....

Have you tried looking at the supplied dlgdemo program, to see if that helps?

A Google search threw up a conversation on this forum: http://bbcbasic.co.uk/forum/viewtopic.php?t=959 that might be useful?

Best wishes,

D

Code: Select all

      INSTALL@lib$+"dlglib"
      MODE 21
      REM Set font according to platform:
      IF INKEY(-256) = &57 THEN
        *FONT Segoe UI,10
      ELSE
        OSCLI "FONT """ + @lib$ + "DejaVuSans"",12"
      ENDIF
      PROC_setdialogpalette
      PROCinit
      END
      :
      DEFPROCinit
      maindlg%=FN_newdialog("New Display",80,60)
      showmain%=FN_showdialog(maindlg%,100,600)
      WAIT 200
      PROC_closedialog(maindlg%)
      ENDPROC

      DEF FN_showdialog(D%,X%,Y%) : LOCAL F%
      LOCAL f%%,H%,I%,l%%,p%%,R%,click%(),ctl{},dlg{}
      DIM click%(2)
      DIM dlg{x%,y%,w%,h%,link%%,focus%%,nctrl%,backcall%%,bmp$,title$,scale}
      DIM ctl{x%,y%,w%,h%,link%%,prev%%,id%,flags%,text$,handler%%}
      PROC_setptr(dlg{},D%+PAGE-!340)

      IF POS REM SDL thread sync.
      IF X%=&FFFFFFFF80000000 dlg.x% = @vdu%!208 - dlg.w%/2            ELSE dlg.x% = (X% + 1) AND -2
      IF Y%=&FFFFFFFF80000000 dlg.y% = @vdu%!212 - @char.y% + dlg.h%/2 ELSE dlg.y% = (Y% + 1) AND -2

      ON MOUSE LOCAL click%() = @msg%,@wparam%,@lparam% : RETURN

      H% = (@char.y% * 3 + 1) AND -2
      dlg.bmp$ = @tmp$ + "dlg" + STR$(TIME) + ".tmp.bmp"
      OSCLI "GSAVE """ + dlg.bmp$ + """ " + STR$dlg.x% + "," + STR$(dlg.y%-dlg.h%) + \
      \     "," + STR$(dlg.w%+2) + "," + STR$(dlg.h%+2+H%)
      GCOL 13
      RECTANGLE FILL dlg.x%,dlg.y%,dlg.w%,H%
      GCOL 15
      MOVE dlg.x% + dlg.w%/2 - FN_stringwidth(dlg.title$)/2,dlg.y% + H% - @char.y%/2
      VDU 5 : PRINT dlg.title$; : VDU 4
      GCOL 0
      RECTANGLE dlg.x%,dlg.y%-dlg.h%,dlg.w%,dlg.h% + H%
      GCOL 7 + 128
      VDU 24,dlg.x%+2;dlg.y%-dlg.h%+2;dlg.x%+dlg.w%-2;dlg.y%;
      VDU 16,30,23,16,64|

      l%% = dlg.link%%
      FOR I% = 1 TO dlg.nctrl%
        IF l%% = 0 EXIT FOR
        PROC_setptr(ctl{},l%%)
        ctl.prev%% = p%%
        ctl.flags% = (ctl.flags% AND NOT WS_DARKMODE) OR F%
        IF ctl.flags% AND WS_TABSTOP IF ctl.flags% AND WS_VISIBLE THEN
          IF (ctl.flags% AND WS_DISABLED) = 0 dlg.focus%% = l%%
        ENDIF
        p%% = l%%
        l%% = ctl.link%%
      NEXT
      ctl.link%% = dlg.link%%
      PRINT ctl.prev%%
      PROC_setptr(ctl{},dlg.link%%)     :REM Crash seems to occur here
      PRINT ctl.prev%%
      ctl.prev%% = p%%

      *REFRESH OFF
      f%% = dlg.focus%%
      IF f%% THEN
        PROC_setptr(ctl{},f%%)
        IF FN(ctl.handler%%)(dlg.x%,dlg.y%,f%%,DLG_GAINFOCUS,0,0)
      ENDIF
      PROC_refreshdialog(D%)

      REPEAT
        R% = FN_polldialog(D%,INKEY(5),click%())
      UNTIL R% > 0

      *REFRESH ON
      f%% = dlg.focus%%
      IF f%% THEN
        PROC_setptr(ctl{},f%%)
        IF FN(ctl.handler%%)(dlg.x%,dlg.y%,f%%,DLG_LOSEFOCUS,0,0)
        dlg.focus%% = 0
      ENDIF

      VDU 24,0;0;@vdu%!208*2-2;@vdu%!212*2-2;4
      = R%

svein
Posts: 44
Joined: Tue 03 Apr 2018, 19:34

Re: It don't work

Post by svein »

First, your dialogue is larger than the output window.
Second, it's empty. You need something in it.
Third, but most important, you can't close showmain%, that's the return value from user choice.
It's maindlg% you need to use in closedialog.

Here's an edited version of your code.

Code: Select all

      PROCinit
      END
      :
      DEFPROCinit
      INSTALL@lib$+"dlglib"

      maindlg%=FN_newdialog("New Display",100,50)
      PROC_button(maindlg%, "OK", 1, 24, 30, 56, 14, 0)
      showmain%=FN_showdialog(maindlg%,&FFFFFFFF80000000,&FFFFFFFF80000000)
      REM WAIT 200
      PROC_closedialog(maindlg%)
      END
Svein

DDRM
Posts: 397
Joined: Mon 02 Apr 2018, 18:04

Re: It don't work

Post by DDRM »

Thanks, Svein - very useful.
D

KenDown
Posts: 261
Joined: Wed 04 Apr 2018, 06:36

Re: It don't work

Post by KenDown »

How interesting! Your program worked, but if I removed the call to PROC_button it threw up the same rather arcane error message! This is not like BB4W, where you can create the dialog box and then add its "furniture" later on.

The problem of the size of the dialog box is less tractable, as I haven't yet found how to enlarge the main window. I guess I'll find it eventually, as I do need such a large dialog box to fit in all the buttons I need.

The other thing I notice is that the WAIT 200 isn't excuted until you click on the "OK" button. Again, that seems completely unlike BB4W, where the main loop polls repeatedly, whether or not an OK button is displayed. This SDLIDE is going to take some getting used to!

Many thanks for your help.