Mixed Programming with Delphi, VB.net, and C #

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.