with-statements

Top  Previous  Next

What is translated > with-statements

 

In C++ there are no with-statements. Therefore all elements must be completely qualified.

 

 

type TDate = record         ->         struct TDate {                              

  Day: Integer;                          int Day;                                  

  Month: Integer;                        int Month;                                

  Year: Integer;                         int Year;                                 

end;                                   };                                          

                                            

procedure test(OrderDate: TDate);      void __fastcall test ( TDate * OrderDate )

begin                                  {                                              

  with OrderDate do                     /*with OrderDate do*/                        

    if Month = 12 then                  if ( OrderDate->Month == 12 )                

    begin                                 {                                          

      Month := 1;                           OrderDate->Month = 1;                    

      Year := Year + 1;                     OrderDate->Year = OrderDate->Year + 1;   

    end                                   }                                          

    else                                else                                         

      Month := Month + 1;                 OrderDate->Month = OrderDate->Month + 1;   

end;                                  }                                              

 

 

At the translation of more complex with-statements a temporary variable is created:

 

                               ->     {                                    

with TMyObject.Create do                /*# with TMyObject.Create do */      

  try                                   TMyObject* tmp2 = new TMyObject;     

    // do something with the object     try                                  

  finally                               {                                    

    Free;                                 // do something with the object    

  end;                                  }                                    

                                        __finally                            

                                        {                                    

                                          tmp2->Free();                      

                                        }                                    

                                      }                                      

 

 

 

 



This page belongs to the Delphi2Cpp Documentation

Delphi2Cpp home  Content