[BLACKBOX] a detail on delegates

From: VDI <bernhardt.gunnar{([at]})nowhere.xy>
Date: Fri, 22 Oct 2010 10:05:17 +0200

----boundary-LibPST-iamunique-1740493836_-_-
Content-type: text/plain

Dear all,

on trying to familiarize myself with .NET I stumble upon a peculiarity
 in Gardens Point CP:

It is perfectly possible to add an instance method to an existing
 delegate:
You can either call a method which takes a procedure variable as
 parameter. The compiler warns you, that procedure variable are
 "deprecated" but the code works fine.

Or you can use the builtin procedures REGISTER, which is specific to
 the .NET implementation of CP. For instance:

(* ------- BEGIN Example 1 ------------- *)
IMPORT
  System := mscorlib_System,
  System_Xml := System_Xml_,
  System_Xml_Schema := System_Xml__Schema;


TYPE
  XmlValidationHandler = POINTER TO RECORD
    ErrorCount: INTEGER
  END;
  
  
PROCEDURE ( this: XmlValidationHandler ) HandleError( sender:
 System.Object; args: System_Xml_Schema.ValidationEventArgs ),NEW;
BEGIN
  INC( this.ErrorCount );
  (* handle the validation error*)
END HandleError;


PROCEDURE Validate( xmlFilename: ARRAY OF CHAR ): BOOLEAN;
VAR
  settings: System_Xml.XmlReaderSettings;
  handler: XmlValidationHandler;
  reader: System_Xml.XmlReader;
BEGIN
  NEW( handler ); handler.ErrorCount := 0;
  NEW( settings );
  settings.set_ProhibitDtd( FALSE );
  settings.set_ValidationType( System_Xml.ValidationType.DTD );
  REGISTER( settings.ValidationEventHandler, handler.HandleError );
  (* create the reader and read xmlFilename for validation *)
  (* ... *)
END Validate;
(* ------- END Example 2 ------------- *)



The compiler won't keep you either from doing the following, which
 results in a null reference exception at run time:
 
(* ------- BEGIN Example 2 ------------- *)
IMPORT
(* same as above *)

TYPE
  XmlValidationHandler = RECORD
    ErrorCount: INTEGER
  END;
  
  
PROCEDURE ( VAR this: XmlValidationHandler ) HandleError( sender:
 System.Object; args: System_Xml_Schema.ValidationEventArgs ),NEW;
(* same as above *)
END HandleError;


PROCEDURE Validate( xmlFilename: ARRAY OF CHAR ): BOOLEAN;
VAR
(* same as above *)
BEGIN
(* same as above *)
  REGISTER( settings.ValidationEventHandler, handler.HandleError );
 (* this fails at runtime with a null-reference exception *)
  (* ... *)
END Validate;
(* ------- END Example 2 ------------- *)


I suspect this could be correct, if CP treated RECORDs as value types
 in .NET.

What I Wonder is: should I report this as a compiler error, even if it
 may be just a minor inconvenience?


yours confusedly
gunnar


----
To unsubscribe, send a message with body "SIGNOFF BLACKBOX" to LISTSERV{([at]})nowhere.xy----boundary-LibPST-iamunique-1740493836_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIERlYXIgYWxsLFxwYXINClxwYXINCm9uIHRyeWlu
ZyB0byBmYW1pbGlhcml6ZSBteXNlbGYgd2l0aCAuTkVUIEkgc3R1bWJsZSB1cG9uIGEgcGVjdWxp
YXJpdHlccGFyDQogaW4gR2FyZGVucyBQb2ludCBDUDpccGFyDQpccGFyDQpJdCBpcyBwZXJmZWN0
bHkgcG9zc2libGUgdG8gYWRkIGFuIGluc3RhbmNlIG1ldGhvZCB0byBhbiBleGlzdGluZ1xwYXIN
CiBkZWxlZ2F0ZTpccGFyDQpZb3UgY2FuIGVpdGhlciBjYWxsIGEgbWV0aG9kIHdoaWNoIHRha2Vz
IGEgcHJvY2VkdXJlIHZhcmlhYmxlIGFzXHBhcg0KIHBhcmFtZXRlci4gVGh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YWx1
ZSB0eXBlc1xwYXINCiBpbiAuTkVULiBccGFyDQpccGFyDQpXaGF0IEkgV29uZGVyIGlzOiBzaG91
bGQgSSByZXBvcnQgdGhpcyBhcyBhIGNvbXBpbGVyIGVycm9yLCBldmVuIGlmIGl0XHBhcg0KIG1h
eSBiZSBqdXN0IGEgbWlub3IgaW5jb252ZW5pZW5jZT9ccGFyDQpccGFyDQpccGFyDQp5b3VycyBj
b25mdXNlZGx5IFxwYXINCmd1bm5hclxwYXINClxwYXINClxwYXINCi0tLS1ccGFyDQpUbyB1bnN1
YnNjcmliZSwgc2VuZCBhIG1lc3NhZ2Ugd2l0aCBib2R5ICJTSUdOT0ZGIEJMQUNLQk9YIiB0byBM
SVNUU0VSVkBMSVNUUy5PQkVST04uQ0h9fQANCiBp
----boundary-LibPST-iamunique-1740493836_-_---
Received on Fri Oct 22 2010 - 10:05:17 UTC

This archive was generated by hypermail 2.3.0 : Thu Sep 26 2013 - 06:30:29 UTC