In order to interact with .Net Objects's methods, properties, Fields and events, you need to create an instance of the object. There are several ways to Create an Instance of a .Net Object in Delphi using the Delphi Framework Library (DFL). These are:
Using Reflection to Create instance of .Net Objects
There are several classes and methods that can be used to create instances of .Net Objects. The mechanism used to create these instances is through reflection. For more information about using Reflection in Delphi using DFL. For more information, see Reflection Overview.
The following methods can be used to create instances of .Net Objects through reflections:
This is a wrapper interface which provides low-level services to all interfaces defined in the Delphi Framework Library and .net objects. The ClrObject interface has methods and properties which allows you to interact with the properties, fields, events and methods of the object to which the interface is wrapped. The process of retrieving the members of the internal object is smooth and fast. For more information see How to Use ClrObject Interface. There are 2 ways to create instances of .Net Objects using the ClrObject. These are:
Using Constructor CoClasses
There are several classes defined in the Runtime library for creating instances of the .net framework types. These classes are called CoClasses. For example, to create an instance of System.io.FileStream(string path, FileMode mode) using Delphi Framework Library (DFL), use the equivalent interface of System.io.FileStream which is _FileStream defined in DFL to create an instance of the _FileStream using the FileStream coClass called coFileStream class. The class has static methods called CreateInstance and each method represent the constructors defined for the System.io.FileStream. For more information see Constructor Classes.
The following code example shows how to write data to a file, byte by byte, and then verify that the data was written correctly using _FileStream Interface.