Silverfrost Forums

Welcome to our forums

call to a call-back function

15 Apr 2011 6:57 #8080

Who can help me. When the cursor is located in the area of the edit box, the ampersand (&) marked accelerator keys “c” ”d” and “e” don’t work. Is it possible to call the call-back function “change_line()” from the function “keyboard_monitor()” or before the stop command? Or exist another solution for this problem? This is only a small example, the original edit box have hundreds of lines.

module edit_modul
character buffer*100
integer*4 e(24),n,i,aus_ein,izeile_anf
common  /e_info/e,n,i,aus_ein,buffer,izeile_anf
end module edit_modul 

WINAPP
program editor
use edit_modul
include<windows.ins>
external  change_line,delete_line,end_line,keyboard_monitor
call add_keyboard_monitor@(keyboard_monitor)

buffer = '1234567890' 
buffer(10:10) = char(0) 
	      i=winio@('%2nl%12.10`eb[vscrollbar,no_hscroll,alt_edit,read_only,no_cursor_snap]&',buffer,1000,e)
i=winio@('%nl%3ta%^14bt[&change_line]&',change_line) 
i=winio@('%nl%3ta%^14bt[&delete_line]&',delete_line) 
i=winio@('%nl%3ta%^14bt[&end_line   ]',end_line)
      
!	if(e(13).eq.1.and.ikey.eq.97) call function change_line() ! Is there a possibility to call this function here??
stop
END

!--------------------------------------
integer function delete_line()
use edit_modul 
include<windows.ins>
call SCROLL_EDIT_BUFFER@(E,1,1)
call edit_delete_lines@(e,1)
delete_line = 1
end

!--------------------------------------
integer function change_line()
use edit_modul 
include<windows.ins>
character buffer1*13

buffer1(1:12) = buffer(1:12)
buffer1(13:13) = char(0)

i=winio@('%12.1eb[no_hscroll]  &',buffer1,1000)
i=winio@('%`6bt[OK]')           	

if(i.eq.1)then
buffer(1:12) = buffer1(1:12)
call window_update@(buffer)
endif
       
change_line = 1
end

!--------------------------------------
integer function end_line()
use edit_modul 
include<windows.ins>
end_line = 0
end
      
!-------------------------------------------
integer function keyboard_monitor()
use edit_modul
include<windows.ins>

ikey = clearwin_info@('KEYBOARD_KEY')
write(*,*)'ikey = ',ikey
if(ikey.eq.99)write(*,*)'c pressed !!!'

!	if(ikey.eq.97) call function change_line() ! Is there a possibility to call this function??

keyboard_monitor=1
end
16 Apr 2011 6:40 #8081

Please add the line between the !!:

buffer = '1234567890' 
buffer(10:10) = char(0) 
!
!
i = winio@('%ca[]%ac[Ctrl+C]%ac[Ctrl+D]%ac[Ctrl+E]&',change_line,delete_line,end_line)
!
!
i=winio@('%2nl%12.10`eb[vscrollbar,no_hscroll,alt_edit,read_only,no_cursor_snap]&',buffer,1000,e)
... 

Regards - Wilfried

16 Apr 2011 9:37 #8083

You can call a callback function just like an ordinary function (which it is!) from any function or subroutine.

Eddie

18 Apr 2011 5:15 #8089

Dear Wilfried, thank you very much for your prompt reply, it works fine. It seems that it is only possible with CTRL+C but not with C alone.

Dear Eddi, please could you give me a short example how to call a callback function out of the above 'integer function keyboard_monitor()'. I don't succeed.

Best Regards Johann

18 Apr 2011 9:26 #8090

Here's an example:

      WINAPP
      PROGRAM E
      EXTERNAL I_FN
      INTEGER  I, I_FN
      INCLUDE <WINDOWS.INS>
      I=WINIO@ ('%ca[Eddie]%^bt[No 1] &', I_FN)
      I=WINIO@ ('%bt[No 2]')
      IF (I .EQ. 2) THEN
          J=I_FN()
          WRITE(*,*) 'Invoked from button 2, return code=', J
          ENDIF
      END
      INTEGER FUNCTION I_FN()
      WRITE(*,*) 'Function was called'
      I_FN = 1
      RETURN
      END

Press button 1, and the function is invoked as a callback. Press button 2, and the function is called as a standard integer function.

Things that can trip you up are: if it is only a callback, you need EXTERNAL but don't need to declare the type. To call as a standard function, you need to declare the type. You must have the () not only when defining the function, but also when calling it as a standard integer function - but not as a callback.

The above is in Fortran-77. You may well do the same thing in a later dialect.

I hope that this is some help.

Eddie

21 Apr 2011 6:12 #8102

Dear Eddie, now I understand how the function works. Thank you very much for your help. Best Regards Johann

21 Apr 2011 3:57 #8103

Hi Johann,

It has been said that the best way to understand something is to explain it to someone else. I have been using EXTERNAL without declaring the function name INTEGER, but I see from an XREF listing that the calling routine thinks the function is DOUBLE PRECISION. Now in practice, this seems not to matter. But I have decided that it is a bad habit, so I am going to go through my codes and make the necessary declarations, just to be on the safe side! So answering your post taught me something.

Until I used Clearwin, I never ever used EXTERNAL, and never passed the name of a FUNCTION to another routine. I had also never used a function which in Fortran 9x wasn't PURE. It took me a very long time to overcome a 30 plus year prejudice to do so!

Good luck with Clearwin - I learn something new every time I use it.

Eddie

Please login to reply.