473,662 Members | 2,752 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to write userdefined callback function

67 New Member
Hi,
i know we can wirte a userdefined callback function..

I had a try for a long time though i feel im near but not able to coin out the exact thing. can any body tell me about a user defined callback function... and a sample on how to write it...


looking forward for a reply..


Thanks in advance for your reply...
Sep 3 '07 #1
6 3165
pbmods
5,821 Recognized Expert Expert
Heya, New Learner.

You may find this article useful.
Sep 3 '07 #2
newlearner
67 New Member
Heya, New Learner.

You may find this article useful.

thx pbmods... The article was useful...

but my doubt is..

whenever http.onreadysta techange value is changed the assigned function is called...

similarly.. i need to create a userdefined handler for ex:
x = somefunction
like onreadystatecha nge(which is a browser object) whenever the value of x is changed thn somefunction should be initiated.

Is this Possible..


looking forward for a reply..

Thanks in advance
Sep 4 '07 #3
gits
5,390 Recognized Expert Moderator Expert
hi ...

so x is a simple js-variable and you want to react with 'somefunction' when the value of x changes?

but i assume you already know WHERE x changes (in case its your own code)? ... everytime a value is assigned to x you may call 'somefunction' or use a set-function for x instead of a simple assignment ... and in that so called 'setter' you may call whatever you want ...

hope i didn't misunderstood your problem?

another method would be to define a watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.watch(property, callback);
  2.  
and to detach the watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.unwatch(property);
  2.  
kind regards
Sep 4 '07 #4
newlearner
67 New Member
hi ...

so x is a simple js-variable and you want to react with 'somefunction' when the value of x changes?

but i assume you already know WHERE x changes (in case its your own code)? ... everytime a value is assigned to x you may call 'somefunction' or use a set-function for x instead of a simple assignment ... and in that so called 'setter' you may call whatever you want ...

hope i didn't misunderstood your problem?

another method would be to define a watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.watch(property, callback);
  2.  
and to detach the watcher:

Expand|Select|Wrap|Line Numbers
  1. obj.unwatch(property);
  2.  
kind regards
tnx for the idea...
I have tried out the way u suggested ... it works fine...

But my doubt is...
we write:
Expand|Select|Wrap|Line Numbers
  1. http.onreadystatechange=response;
response is triggered whenever onreadystatecha nge is chnged from 0 .. 4.

similarly... i write
Expand|Select|Wrap|Line Numbers
  1. function base() {
  2.   this.x=0;
  3. }
  4.  
  5. base = new base()
  6.  
  7. function tst(){
  8.   base.x = callfun;
  9. }
in a html page i have 2 buttons

on a 1st onclick event i say base.x=1// I need callfun to be triggered (coz x has changed)
on a 2nd onclick event i say base.x=2// I need callfun to be triggered (coz x has changed)

Is This possible...?


Looking for ward fir a reply..

Thanks in advance
Sep 4 '07 #5
acoder
16,027 Recognized Expert Moderator MVP
Please use CODE tags when posting code, e.g.
[code=javascript]Javascript code goes here[/code.] (remove the dot).
Sep 4 '07 #6
gits
5,390 Recognized Expert Moderator Expert
hi ...

have a look at the following example:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function OBJ() {
  3.     this.x = 0;
  4. }
  5.  
  6. OBJ.prototype.increment_val = function() {
  7.     this.x++;
  8. }
  9.  
  10. var obj = new OBJ;
  11.  
  12. obj.watch('x', function(val, oldval, newval) {alert(newval); return newval;});
  13. </script>
  14.  
  15. <a href="#" onclick="obj.increment_val();">increase obj counter</a>
  16.  
kind regards

ps: note watch will not work with IE ... so the 'setter'-method is probably to be preferred :)
Sep 4 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2048
by: ma740988 | last post by:
// file sltest.h #ifndef SLTEST_H #define SLTEST_H class CallbackBase // herb shutters gotW source .. { public: virtual void operator()() const { }; virtual ~CallbackBase() = 0; };
7
2747
by: Remi Bastide | last post by:
I'm trying to open a blank window and write a message in it. The following page works as expected in IE, but in Firefox the message is not written: <HTML> <HEAD> <TITLE>Document.write bug</TITLE> <Script Language="JavaScript"> function load() { var w = window.open('','','');
2
2697
by: Adam | last post by:
This is frustrating me. Opening IE displays the following code fine. When I open a new window the code no longer works. All the HTML is overwritten with the first document.write statement. Tried with window tried without Please help. This code pulls XML from a web site then parses it into a dynamically created table built with javascript. The write table is not working correctly, other methods work fine. This code also locks up Fire Fox...
15
1993
by: Felix Kater | last post by:
Hi, in a given library I register callback functions with this function: bool set_callback(int index, int (*callback_function)(long)); I need the callback function to also pass the index which is, however, not (re-)passed by the callback function. Normally, I would just register callback functions for each
0
9970
by: Steve - DND | last post by:
We are continually receiving timeout, and "Unable to write data to the transport connection" errors while using the System.Net.HttpWebRequest class from an ASP.Net web page. Below are the two errors we continue to receive: Source: System Message: The operation has timed-out. Target Function: System.Net.WebResponse GetResponse()
3
1952
by: Wen | last post by:
hello, now, i wanna port a c++ program into C# project. a DLL written by C++ and keep it no change, and UI wirtten by C#. my C++ UI code is as below: // error handlers --global function callback function // C++ dll would invoke this function if needed void ImageConv_Callback_Handler(const char *szInfo) {
11
1444
by: Jia Lu | last post by:
HI all I am making an application with wxpython. But I got a problem when I want to change the display string according to process status. I passed the frame to the processing function and use the frame.txtobj to change displaying strings. I found it is a bad method to do that.
0
1394
by: Erwin Moller | last post by:
Hi group, I found something strange in PHP5.2.4 (on IIS7/Vista). I am working on an app that has been running just fine under heavy load for over a year at some custumer of mine. (they have PHP5.1 on W2003 Server, ISAPI) I imported the whole project locally on a slightly more modern version of PHP 5.2.4 to make a few adjustments.
2
1685
by: SnehaAgrawal | last post by:
Does anyone know how to call a UserDefined Function written in SQL 2000 from program(I mean I am writing code in VB.net)..I know how to call it from a stored proc. but don't know how to call from my prog. Like we call stored proc. Thnks
0
8435
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8857
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8633
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7368
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6186
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5655
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4181
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4348
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2763
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.