[fpc-pascal]Calling Procedures via pointers
Hi, I've been away from Pascal for about 10 years now and have just started to get back into it. So, spank me hard and call me a newbie if you must... Anyhow, onto the problem... I'm designing a unit (and a little test application) that i want to add a call back function to (as exit code)... i.e. The program gives the unit a pointer to the procedure MyCallback When an error occurs when the unit is communicating to the device (for example a serial device) if the pointer pCallback is not NIL I'd like to be able to call the user defined procedure, in this case MyCallBack. The idea is that I can compile the unit, then define the exit code in my individual applications... can someone give me some pointers (pun intended) on how to go about it Many thanks Andy below is the sort of thing i'm trying to do... in program: Procedure MyCallback(); Begin {do some stuff then} Halt; End; in unit: Procedure SetCallBack(pProc : Pointer); Begin pCallBack := pProc; End; { Carry out the procedure the user defined} Procedure DoCallBack; Begin If (pCallBack<>NIL) then {Call the users procedure} else Halt; End; ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Calling Procedures via pointers
At 22:50 29/10/2003, Anton Tichawa wrote: Hello, Andy! Pascal supports procedure types, which are more reliable compared to untyped pointers. Procedure types also distinguish the types of the procedure's parameters (which is not important for your parameterless callback procedure). My suggestion is: Hey Anton! You're a Star! I made a minor change (using SetCallBack(@MyCallBack);) and it appears to be working REALLY well, I just need to test my application... Many thanks indeed, you saved me there!! And such a quick response too :D Thanks!!! Andy ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal
Re: [fpc-pascal]Calling Procedures via pointers
At 15:05 30/10/2003, you wrote: At 22:50 29/10/2003, Anton Tichawa wrote: Hello, Andy! Pascal supports procedure types, which are more reliable compared to untyped pointers. Procedure types also distinguish the types of the procedure's parameters (which is not important for your parameterless callback procedure). My suggestion is: Hey Anton! You're a Star! I made a minor change (using SetCallBack(@MyCallBack);) and it appears to be working REALLY well, I just need to test my application... Many thanks indeed, you saved me there!! And such a quick response too :D Thanks!!! Andy Ok, ok, I spoke too soon - it didn't work :'( Andy ___ fpc-pascal maillist - [EMAIL PROTECTED] http://lists.freepascal.org/mailman/listinfo/fpc-pascal