Reproduced to: http://www.cnblogs.com/zhenyulu/articles/53834.html
The. net lecture on the evening of this week was canceled because it was in conflict with my course and was not allowed to stop the course in the last 20 days. So I can only pre-publish some of the demo content in my lecture here.
One of the demonstration content is "the same platform, multi-language ". Programs Written in different languages on the. net CLR platform can call each other. The UML diagram is as follows:
We use Delphi 8 to compile the Person class and compile it into a DLL file. The Code is as follows:
Unit TPerson;
Interface
Type
Person = class
Private
{Private Declarations}
Public
Name: string;
Age: integer;
Constructor Create;
End;
Implementation
Constructor Person. Create;
Begin
Inherited Create;
End;
End.
Add a reference to the DLL written in Delphi in VB. NET and write the Employee class inherited from the Person class.
Imports System
Public Class EmployeeClass Employee
Inherits TPerson. Person
Public Salary As Int32
Public Sub Show ()
Console. WriteLine ("The Name is:" & Me. Name)
Console. WriteLine ("The Age is:" & Me. Age)
Console. WriteLine ("The Salary is:" & Me. Salary)
End Sub
End Class
The following work is to use C # To write code to call the DLL generated by Delphi and VB. NET. Add the references of the two DLL files to the project respectively, and then compile the calling program:
Using System;
Using TEmployee;
Public class Client
{
Public static void Main ()
{
Employee e = new Employee ();
E. Name = "Tom ";
E. Age = 22;
E. Salary = 1500;
E. Show ();
}
}
So far, the program has been compiled. Let's take a look at the effect. Complete program code can be downloaded from here.