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#

 

                                                          using System;                                                 

                                                          using static System.SystemInterface;                          

                                                          using static Test.TestImplementation;                         

                                                          using static Test.TestInterface;                              

                                                                                                                        

                                                                                                                        

                                                          namespace Test                                                

unit Test;                                                {                                                             

                                                                                                                        

                                                                                                                        

interface                                                 public class TestInterface                                    

                                                          {                                                             

type                                                                                                                    

  TFoo = class                                              public class TFoo : TObject                                 

  private                                                   {                                                           

    procedure foo;  // member function declaration           // member function definition                              

  end;                                                        private void foo()                                        

                                                              {                                                         

                                                              }  // member function declaration                         

                                                                                                                        

                                                              public TFoo() {}                                          

                                                            };                                                          

const                                                       public const int foo = 0;   // interface constant           

  foo = 0;   // interface constant                                                                                      

                                                          // interface variable                                         

// interface variable                                       public static int interface_variable = 0;                   

var interface_variable : integer = 0;                       public static void foo_proc()                               

                                                            {                                                           

  procedure foo_proc;  // free function declaration         }  // free function declaration                             

                                                                                                                        

                                                          } // class TestInterface                                      

                                                                                                                        

                                                                                                                        

                                                                                                                        

                                                          file class TestImplementation                                 

implementation                                            {                                                             

                                                                                                                        

const                                                       public const int bar = 0;   // implementation constant      

  bar = 0;   // implementation constant                                                                                 

                                                          // implementation variable                                    

// implementation variable                                  public static int implementation_variable = 0;              

var implementation_variable : integer = 0;                                                                              

                                                            public class TBar : TObject                                 

type                                                        {                                                           

                                                             // member function definition                              

TBar = class                                                                                                            

private                                                       private void foo()                                        

    procedure foo;  // member function declaration            {                                                         

end;                                                          }  // member function declaration                         

                                                                                                                        

                                                              public TBar() {}                                          

procedure TFoo.foo;   // member function definition         };                                                          

begin                                                                                                                   

end;                                                        public static void bar_proc()                               

                                                            {                                                           

procedure foo_proc;                                         }       // free function definition                         

begin                                                     } // class TestImplementation                                 

end;                                                                                                                    

                                                          }  // namespace Test                                          

procedure TBar.foo;   // member function definition                                                                     

begin                                                                                                                   

end;                                                                                                                    

                                                                                                                        

procedure bar_proc;       // free function definition                                                                   

begin                                                                                                                   

end;                                                                                                                    

                                                                                                                        

end.                                                                                                                    

              

                                  

                                                                                                                                                        

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