File layout |
Top Previous Next |
What is translated > File layout
Delphi2C# creates for each Delphi source file an according C# target file. Records and classes of the Delphi interface part, simply become according records and classes in the generated C# file. But in contrast to Delphi in C# constants, variables and routines cannot be declared outside of a class.Therefore in C# two classes are declared, which contain the global elements as static members. The first of these classes contains the constants, variables and routines of the Delphi interface part and the second class those of the implementation part. If there are records or classes declared in the implementation part of the Delphi code, theses element also become member of the second class.
In the following example the placements of typical code elements in Delphi on the one side and in C# on the other side are contrasted:
Delphi C#
unit test; using static test.testInterface; using static test.testImplementation; interface using System; using static System.SystemInterface;
namespace test { public class TFoo : TObject type { TFoo = class private void foo() private { procedure foo; } end; public TFoo() {} };
public class testInterface { const foo = 0; public const int foo = 0; procedure foo_proc; public static void foo_proc() { }
} // class testInterface
implementation public class testImplementation { const bar = 0; public const int bar = 0;
type TBar = class public class TBar : TObject private { procedure foo; private void foo() end; { }
public TBar() {} }; procedure TFoo.foo; begin end;
procedure foo_proc; begin end;
procedure TBar.foo; begin end;
procedure bar_proc; public static void bar_proc() begin { end; }
end. } // class testImplementation
} // namespace test
This diagram also shows, that in C# there is no difference between declaration and implementation of a routine;. the function body of a routines is written immediately at the place where the Delphi declaration had been.
At the beginning of the C# file there are two uses clauses, which allow the use of the public elements of testInterface and of testImplementation inside of the whole file test.cs without qualification. Next System.cs is included, so that the classes, constants and routines which correspond to the according entities of the Delphi system can be used without qualification too. Finally with the clause "using static System.SystemInterface" the constants, variables and routines of the interface part of the System namespace can be accessed. There is an option to create a common file of global using directives instead of inserting them into the according single files.
Comments can appear at many places in a file,
|
This page belongs to the Delphi2C# Documentation |
Delphi2C# home Content |