GetRef function
Returns a reference to a procedure that can bind an event.
Set object.eventname = GetRef (procname)
Parameters
Object
Required option. The name of the object to which the event is associated.
EventName
Required option. The name of the event to bind to the function.
ProcName
Required option. The string contains the name of the Sub or Function procedure, which is associated with the event.
Description
The GETREF function can be used to associate a VBScript procedure (function or Sub) with any event available on a DHTML (Dynamic HTML) page. The DHTML object model provides information about various available events for different objects.
In other scripting and programming languages, the functionality provided by GETREF is called a function pointer, which points to the address of the procedure to be executed when the specified event occurs.
The following example illustrates the use of the GETREF function:
Copy Code code as follows:
<script language= "VBScript" >
Function Getreftest ()
Dim Splash
Splash = "Getreftest Version 1.0" & VbCrLf
Splash = Splash & CHR (169) & "YourCompany 1999"
MsgBox Splash
End Function
Set window.onload = GetRef ("Getreftest")
</SCRIPT>
Probably meant to be used for binding events, because I don't know much about the events in the ASP, so I don't have much discussion about the relationship between GETREF and events here. Only the use of GETREF in Web development applications is studied here.
In PHP, PHP does not support pointers, so it is not possible to use the technique of function pointers. PHP supports so-called "function variables", which give a function a variable that acts like a function pointer.
Examples of simple points:
PHP can do this
Copy Code code as follows:
<?php
$funcname = "Cutstr";
Echo $funcname ();
function Cutstr () {
return "function";
}
?>
With the getref, similar to the above features ASP can also be implemented:
<%
Dim funcname
FuncName = "Cutstr"
Response. Write (Getref (funcname))
function Cutstr ()
Cutstr = "function"
End Function
%>
Practical application:
In the background management of the project, such as news add, delete, modify, and other operations in the same page processing, generally we will insert a hidden field action in the form, or URL parameter action, according to the value of the action to determine which step. Usually write this:
Select Case Request.QueryString ("action")
Case "Add": ' The code snippet to manipulate ....
Case "Modify": ' The code snippet to operate ....
End Select
or use if Else
Use function variables to make your code more concise and clear, with a complete example, which is a common operation in the background. Modify, delete, Add.
You can use the ACTION=XXX to test the results.
Copy Code code as follows:
<%
Option Explicit
Dim array_action
' Valid module name
array_action = Array ("list", "Add", "Add_form", "Modify", "Modify_form", "Del")
' Output
Response.Write (Getref (action))
' Verify that the parameters are valid
Function action ()
Dim Str:str = Request.QueryString ("action")
Action = array_action (0)
If Arr_in (array_action,str) then action = str
End Function
' Operation part----------------------
Function List ()
List = "Show listing Information"
End Function
function Add ()
Add = "Add Action"
End Function
function Add_form ()
Add_form = "Show Add Forms"
End Function
function Modify ()
Modify = "Perform modify operation"
End Function
'------------------------------
' Detect if it exists in an array
function arr_in (a,v)
Arr_in = False
Dim i
If IsArray (a) Then
For each i in a
If i = v then:arr_in = true:exit For:end If
Next
End If
End Function
%>
Many posts discussed ASP, PHP,. NET, in the end which is strong, personally think is not a language problem, but the idea of the problem, the principle of Web site understanding, with what language to write all the same, efficiency is not high, the code is concise and clear, then look at their level. Welcome you to discuss!