Parameter types

Top  Previous  Next

What is translated > Routines > Parameter types

 

Parameters either are passed to routines by value or be reference.Strings are passed as references, but behave as if they were passed by value (because of its copy-on-write technique). Further there are constant parameters and untyped parameters: Different cases of single parameters and how they are converted are listed below. Array parameters are discussed in the array section.

 

 

type

 

MyRecord = record

end;

 

PInteger = ^Integer;

 

 

procedure Foo(param : Integer);

procedure Foo(const param : Integer);

procedure Foo(var param : Integer);

procedure Foo(out param : Integer);

 

procedure Foo(param : String);

procedure Foo(const param : String);

procedure Foo(var param : String);

procedure Foo(out param : String);

 

procedure Foo(param : Pointer);

procedure Foo(const param : Pointer);

procedure Foo(var param : Pointer);

procedure Foo(out param : Pointer);

 

procedure Foo(param : PChar);

procedure Foo(const param : PChar);

procedure Foo(var param : PChar);

procedure Foo(out param : PChar);

 

procedure Foo(param : PInteger);

procedure Foo(const param : PInteger);

procedure Foo(var param : PInteger);

procedure Foo(out param : PInteger);

 

procedure Foo(param : MyRecord);

procedure Foo(const param : MyRecord);

procedure Foo(var param : MyRecord);

procedure Foo(out param : MyRecord);

 

// untyped parameters 

procedure Foo(const param);

procedure Foo(var param);

procedure Foo(out param);

 

->

 

 

->

 

   C++Builder                                          Other compilers

 

void __fastcall Foo(int param);                     void Foo(int param);                           

void __fastcall Foo(int param);                     void Foo(int param);                     

void __fastcall Foo(int& param);                    void Foo(int& param);                          

void __fastcall Foo(int& param);                    void Foo(int& param);                          

void __fastcall Foo(System::String param);          void Foo(System::String param);                

void __fastcall Foo(const System::String& param);   void Foo(const System::String& param);         

void __fastcall Foo(System::String& param);         void Foo(System::String& param);               

void __fastcall Foo(System::String& param);         void Foo(System::String& param);               

void __fastcall Foo(void* param);                   void Foo(void* param);                         

void __fastcall Foo(const void* param);             void Foo(const void* param);                   

void __fastcall Foo(void*& param);                  void Foo(void*& param);                        

void __fastcall Foo(void*& param);                  void Foo(void*& param);                        

void __fastcall Foo(System::PChar param);           void Foo(System::PChar param);                 

void __fastcall Foo(const System::PChar param);     void Foo(const System::PChar param);           

void __fastcall Foo(System::PChar& param);          void Foo(System::PChar& param);                

void __fastcall Foo(System::PChar& param);          void Foo(System::PChar& param);                

void __fastcall Foo(PInteger param);                void Foo(PInteger param);                      

void __fastcall Foo(const PInteger param);          void Foo(const PInteger param);                

void __fastcall Foo(PInteger& param);               void Foo(PInteger& param);                     

void __fastcall Foo(PInteger& param);               void Foo(PInteger& param);                     

void __fastcall Foo(const MyRecord& param);         void Foo(const MyRecord& param);                      

void __fastcall Foo(const MyRecord& param);         void Foo(const MyRecord& param);               

void __fastcall Foo(MyRecord& param);               void Foo(MyRecord& param);                     

void __fastcall Foo(MyRecord& param);               void Foo(MyRecord& param);                     

                                                                                                   

// untyped parameters                               // untyped parameters                          

void __fastcall Foo(const void* param);             void Foo(const void* param);                   

void __fastcall Foo(void** param);                  void Foo(void** param);                        

void __fastcall Foo(void** param);                  void Foo(void** param);                        

 

 

 

Passing a record by value is a special case. The record may be changed inside of the routine, but the change may not have an effect outside of the routine. Therefore Delphi2Cpp passes the parameter as a constant reference, but automatically creates a copy of the parameter inside of the routine. The original parameter is renames to avoid a conflict. E.g.:

 

void Foo(const MyRecord& cparam)

{

  MyRecord param = cparam;

 

 

 

There is a problem with var pointer parameters. If a pointer of a special type is passed the C++ compiler will produce an error. For example:

 

 

void* ReallocMem(void*& P, size_t Size);

 

char* buf;

 

ReallocMem(buf, 10); // error: conversion from char* into "void *&" isn't possible

 

 

That's the reason, why C++Builder doesn't knows ReallocMem, but only ReallocMemory:

 

void * __cdecl ReallocMemory(void * P, NativeInt Size);

 

A good solution for Delphi2Cpp II would be to define ReallocMem as a template function like:

 

template <typename T>

void ReallocMem(T*& P, size_t Size)

{

  ...

 

But this could be a solution for special functions of the RTL/VCL only. Non-template user routines hardly can be converted into routines with templates, because this would require to move them together with their implementations into the header. Therefore the solution above has been chosen for  Delphi2Cpp II. In cases where such routines are used, Delphi2Cpp II automatically inserts a typecast for the parameter:

 

ReallocMem((void*&) Buf, 10);

 

Untyped var-parameters are converted to void** parameters. An address is passed as argument and inside of the routine the parameter is dereferenced.

 

 

 

 

 

 

 

 

 

 



This page belongs to the DelphiXE2Cpp11 Documentation

DelphiXE2Cpp11 home  Content