Note: This website is archived. For up-to-date information about D projects and development, please visit wiki.dlang.org.

Changes from Version 1 of DelegatesWithinObjectsExample

Show
Ignore:
Author:
jcc7 (IP: 68.97.93.38)
Timestamp:
11/12/05 04:58:15 (18 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • DelegatesWithinObjectsExample

    v0 v1  
     1= Delegate Within Object Example = 
     2 
     3''Part of'' DelegateCategory 
     4 
     5== Description == 
     6 
     7A simple example of how to use delegates within objects, as delegates are usually used for GUI event handling such as in Delphi or C#. 
     8 
     9== Example == 
     10 
     11{{{ 
     12#!d 
     13// Simple sample: how to use delegates within objects 
     14 
     15import std.c.stdio; 
     16 
     17// DelegateClass: a class with declared delegate function "printText" 
     18class DelegateClass  
     19{ 
     20    public void delegate(char[] ) printText; 
     21} 
     22 
     23int main() 
     24{ 
     25    // Function print 
     26    void print(char[] text) { printf(text); } 
     27 
     28    // Initialize a DelegateClass 
     29    DelegateClass delclass = new DelegateClass(); 
     30 
     31    // Assign the delegate "printText" to function "print" 
     32    delclass.printText = &print; 
     33 
     34    // Call printText to test 
     35 
     36    delclass.printText("HELLO\n"); 
     37 
     38    return 0; 
     39} 
     40}}} 
     41 
     42== Source == 
     43 
     44|| Link || http://www.dsource.org/tutorials/index.php?show_example=102 || 
     45|| Posted by || Anonymous || 
     46|| Date/Time || Fri Jun 25, 2004 2:49 am ||