📜 ⬆️ ⬇️

Application Migration - Code Examples

This article, on the one hand, was originally conceived as a continuation of my first article, “Application Migration — Myths and Reality, ” and on the other hand, the answer to some of the comments that were asked in the Habravchane article vladsharikov , lair and berez .

Code Conversion from Delphi to C #


To begin with, I will give an example of converting code in Delphi to C # code:
Delphi code
unit Unit3; interface type TMyClass = class _str: string; constructor Create; procedure setStr(s2: string); public class var FClassField: integer; end; TMyClassD = class of TMyClass; procedure DoSomeThing; implementation procedure DoSomeThing; begin end; { TMyClass } constructor TMyClass.Create; var c: char; i: byte; cod: integer; s: string; cls: TMyClassD; begin cls := TMyClass; inherited; DoSomeThing; Val('5', i, cod); c := '1'; s := c; end; var cls: TMyClass; s: string; procedure TMyClass.setStr(s2: string); begin s2[4] := 'a'; end; initialization cls := TMyClass.Create; s := '123456'; cls._str := s; s[3] := '0'; cls.setStr(s); end. 


After the broadcast, the code turns into this:
C # code
 using System; using System.Runtime.InteropServices; using System.Collections.Generic; using System.Data; using System.Linq; using System.IO; using System.Text; using FastCode.Delphi.Core._System; namespace Project3 { public static partial class Unit3_Module { public static void Unit3_Initialization_() { cls = TMyClass.Create(); s = "123456"; cls._str = s; //s[3] = '0'; s = s.Substring(0, 2) + '0' + s.Substring(3); cls.setStr(s); } public static void DoSomeThing() { } internal static TMyClass cls; internal static string s; } public partial class TMyClass : TObject { public override void __Create__() { Char c; byte i; int cod; string s; Class_of_TMyClass cls; cls = Class_of_TMyClass.Instance; base.__Create__(); Unit3_Module.DoSomeThing(); System_Module.Val('5'.ToString(), out i, out cod); c = '1'; s = c.ToString(); } public void setStr(string s2) { //s2[4] = 'a'; s2 = s2.Substring(0, 3) + 'a' + s2.Substring(4); } public static TMyClass Create() { TMyClass _instance = new TMyClass(); _instance.__Create__(); return _instance; } public string _str; public static int FClassField; } public partial class Class_of_TMyClass { protected Class_of_TMyClass() { } public TMyClass Create() { return TMyClass.Create(); } public static Class_of_TMyClass Instance = new Class_of_TMyClass(); public int FClassField { get { return TMyClass.FClassField; } set { TMyClass.FClassField = value; } } } } 


And yes, the C # code works after connecting the migration library and compiling.
There are more complex and interesting places - for example, the implementation of properties with indices (if anyone knows Delphi - they will understand) that can be accessed by name, that is, in the form Obj.Items [index], but right now there is no such code at hand.

FoxPro Appearance


I quickly added a small application on FoxPro, it turned out like this:

Appearance in C # + WPF below.
Sorry - full themes, with replaceable buttons on the window title and interchangeable header styles, didn’t look for


Here are three additional topics.

Glass

Steel blue gradient

Metro Light

If there are more questions on conversion examples - please in the comments.
PS Translation from Delphi to C # is one of the test projects that were used in the converter debugging process.
PPS The form on FoxPro is made hastily, especially for demonstration.

')

Source: https://habr.com/ru/post/260023/


All Articles