PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Vocabulary
  • How to use a.Net delegate with WINDEV?
  • How to process the .NET events
  • How to process the .NET events in Windows Phone
  • Tip
  • Various
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
DotNetDelegate (Function)
In French: DotNetDélégué
Initializes a .NET delegate. This delegate will allow .NET to call back a WLanguage procedure or method in case of events or "callbacks".
Versions 16 and later
WINDEV Mobile This function is now available for the Windows Phone applications.
New in version 16
WINDEV Mobile This function is now available for the Windows Phone applications.
WINDEV Mobile This function is now available for the Windows Phone applications.
clOwn is OwnEvent
clOwn:add_MyEvent(DotNetDelegate("MyHandler", "EventHandler<MyEventArgument>"))
clOwn:Trigger("Hello")
PROCEDURE MyHandler(src, args)
Trace(args:Message)
Syntax
<Result> = DotNetDelegate(<WLanguage Procedure> , <Type of Delegate>)
<Result>: .NET object
.Net object of the delegate type.
<WLanguage Procedure>: Character string (with or without quotes)
Name of the WLanguage procedure or method to call. This procedure has the following format:

PROCEDURE <Procedure Name>(Src, Args)
where:
  • Src corresponds to the .NET object that sends the event
  • Args corresponds to the .NET object used as parameter of the event.
<Type of Delegate>: Character string (with quotes)
Name of the class of the delegate to create. This parameter must not correspond to a variable.
Remarks

Vocabulary

  • Delegate: Used to manage a callback. It is a "function" type. It defines the prototype of the function. The delegate is initialized with a .NET function corresponding to the prototype. The delegate is the .NET equivalent of the function pointer in C. Several methods can be associated to the same delegate : all of them will be called.
    Caution : in the .NET documentation, this term can also designate the "delegates methods", which means the methods associated with a delegate.
  • Handler: Particular type of delegate specifically designed for processing events.
  • Event: An event can be associated with one or more handlers. When the event is triggered, all the handlers associated with this event are called.

How to use a.Net delegate with WINDEV?

To use a .Net delegate with, you must:
  1. Find the deleguate in the list of .NET classes
    The delegate is a .NET class itself. The name of the delegate must be known (see the documentation of your.NET assembly).
  2. Define the parameters of the delegate
    The delegate defines an Invoke method. The WLanguage procedure associated with the delegate must have the same parameters.
  3. Associate the WLanguage procedure with the delegate
    The delegate is used in a .NET class. This class owns methods used to add or remove a "delegate method" to/from the delegate.
    See the documentation about your .NET assembly to find out the names of these methods.
Example:
  • Name of the class that uses the delegate  : CUseDelegate
  • Name of the class of the delegate: CUseDelegate.CpfMyDelegate
  • Prototype of the Invoke method of the CUseDelegate.CpfMyDelegate class : Invoke(integer)
  • Prototype of the corresponding WLanguage method : Procedure MyCallbackWL(local i is int)
    // Instantiate a class that owns a delegate
    clUse is CUseDelegate

    // Add a "delegate method" (WL callback) to the delegate
    clUse:AddDelegate(DotNetDelegate("MyWLCallback", ...
    "CUseDelegate.CpfMyDelegate"))

    // Provoke the use of the delegate by the .NET class
    clUse:UseDelegate()
WINDEVWEBDEV - Server codeReports and QueriesWindowsWindows MobileAjaxUser code (UMC)

How to process the .NET events

To process the .Net events, you must:
1. Find the event.
The event is a member of a .NET class. This member has a name and a type. The type defines the type of the handler that can be associated with the event. The name is used to find two methods:
  • "add_<Event name>"
  • "remove_<Event name>"
These two methods are used to associate and dissociate one or more handlers with/from an event. The type of the parameter for these two methods is the name of the handler type.
Example: The OwnEvent class contains a MyEvent event whose type is EventHandler<MyEventArgument>.
2. Retrieve a handler.
A handler is retrieved by DotNetDelegate:
  • The first parameter is the name of the WLanguage procedure
  • The second parameter is the name of the class of the handler type. This name can be retrieved by the name of the type of parameters of "add_xxx" and "remove_xxx" methods.
Example: The WLanguage procedure has the following format:
PROCEDURE MyHandler(src, args)
Trace(args:Message)
src is a .NET object of OwnEvent type, args is a .NET object of MyEventArgument type
3. Associate the handler with the event
To associate the handler with the event, all you have to do is call the "add_<Event Name> method on the object that owns the event".
Example:
clOwn:add_MyEvent(DotNetDelegate("MyHandler", "EventHandler<MyEventArgument>"))
4. Trigger the event
In our example, the call to clOwn:Trigger triggers the event.
WINDEV Mobile

How to process the .NET events in Windows Phone

To process the .Net events, you must:
1. Find the event.
The event is a member of a .NET class. This member has a name and a type. The type defines the type of the handler that can be associated with the event.
Example: The OwnEvent class contains a MyEvent event whose type is EventHandler<MyEventArgument>.
2. Retrieve a handler.
A handler is retrieved by DotNetDelegate:
  • The first parameter is the name of the WLanguage procedure
  • The second parameter is the name of the class of the handler type. This name can be retrieved by the name of the type of the event member of the .NET class.
Example: The WLanguage procedure has the following format:
PROCEDURE MyHandler(src is System.Object, args is EventHandler<MyEventArgument>)
src is a .NET object of OwnEvent type, args is a .NET object of MyEventArgument type
3. Associate the handler with the event
To associate the handler with the event, all you have to do is use the "+=" operator of .NET on the event member.
Example:
clOwn.MyEvent += DotNetDelegate("MyHandler", "EventHandler<MyEventArgument>"))
4. Trigger the event
In our example, the call to clOwn:Trigger triggers the event.

Tip

In the WLanguage procedure, you can:
  • use the methods associated with the parameters of the procedure. However, the completion is not available.
  • define a dynamic object and assign the requested parameter to it. The completion is available for the object.
These two methods are used in the detailed example.

Various

This function cannot be used in dynamic compilation.
Related Examples:
WD DirectoryObserver Training (WINDEV): WD DirectoryObserver
[ + ] This example presents the use of the WLanguage function named fTrackDirectory.
It is used to watch a directory,
which means to be informed whenever a modification is performed in this directory.
A modification can be:
- Adding a file or a directory
- Renaming
- Modifying a file
- Deleting a file
WD DOTNET Delegate Training (WINDEV): WD DOTNET Delegate
[ + ] This educational example explains how to interact with the DOTNET delegates
Components
WINDEVWEBDEV - Server codeReports and Queries wd230vm.dll
Windows Mobile wp230vm.dll
See also
Minimum required version
  • Version 12
This page is also available for…
Comments
Click [Add] to post a comment