forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

call to a call-back function

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
Bartl



Joined: 16 Oct 2009
Posts: 58
Location: München

PostPosted: Fri Apr 15, 2011 7:57 pm    Post subject: call to a call-back function Reply with quote

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.
Code:

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

Back to top
View user's profile Send private message
Wilfried Linder



Joined: 14 Nov 2007
Posts: 314
Location: Düsseldorf, Germany

PostPosted: Sat Apr 16, 2011 7:40 am    Post subject: Reply with quote

Please add the line between the !!:

Code:
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
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Sat Apr 16, 2011 10:37 pm    Post subject: Reply with quote

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

Eddie
Back to top
View user's profile Send private message
Bartl



Joined: 16 Oct 2009
Posts: 58
Location: München

PostPosted: Mon Apr 18, 2011 6:15 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Mon Apr 18, 2011 10:26 pm    Post subject: Reply with quote

Here's an example:

Code:
      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
Back to top
View user's profile Send private message
Bartl



Joined: 16 Oct 2009
Posts: 58
Location: München

PostPosted: Thu Apr 21, 2011 7:12 am    Post subject: Reply with quote

Dear Eddie,
now I understand how the function works.
Thank you very much for your help.
Best Regards
Johann
Back to top
View user's profile Send private message
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu Apr 21, 2011 4:57 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group