Board index » cppbuilder » delphi to bcb

delphi to bcb

Can someone tell me if this is the correct translation.

function TForm1.GetParameterTypeAsString(  varType : TVarType ) :
String;
begin
   case varType of
      VT_UI1:   Result := 'VT_UI1';

AnsiString __fastcall TForm1::GetParameterTypeAsString(Word varType)
{
    switch( varType )
    {
        case VT_UI1:
            return "VT_UI1";
            break;

Thanks......

 

Re:delphi to bcb


You got it right.

Gambit

Quote
"Terry James" <t...@sundance.com> wrote in message news:3b4f3b40_1@dnews...
> Can someone tell me if this is the correct translation.

Re:delphi to bcb


Close, but I'll make a couple of suggestions.

1st:  I don't use __fastcall unless it is forced on me by the VCL.  This
is a 100% change of policy from when I first migrated from Delphi to
BCB, but generally the C++ seems easier and cleaner if I ignore the VCL
extensions in my regular code (even methods on forms.)

More importantly, I would use a reference paramater rather than a word
(although I don't know what variable type TVarType is)

AnsiString TForm1::GetParameterTypeAsString( TVarType &varType )

Passing by reference is equivalent to Delphi variable paramaters, if you
change varType within the method, then the passed variable is changed.
In your version, any changes to varType will not be passed back out.

On the subject of references, it is quite common to pass const
recerences in C++ as follows:

AnsiString TForm1::GetParameterTypeAsString( const TVarType &varType )

This is done for efficiency reasons, as passing objects by reference
avoids creating extra copies, and using const the compiler will catch
any unexpected attempts to change the initial value.  However, this is
generally less efficient for the simple built-in types (int/word/bool
etc) as you are effectively passing a pointer, which in these cases is
slower than passing the variable!

So your answer will be correct if GetPArameterTypeAsString never
modifies varType, and if it can safely be converted to a word, and there
is nothing in your example to suggest this is not the case.  But I
thought I ought to cover the other possibilities :? )

--
AlisdairM
Team Mongolian Wok

Quote
Terry James wrote:
> Can someone tell me if this is the correct translation.

> function TForm1.GetParameterTypeAsString(  varType : TVarType ) :
> String;
> begin
>    case varType of
>       VT_UI1:   Result := 'VT_UI1';

> AnsiString __fastcall TForm1::GetParameterTypeAsString(Word varType)
> {
>     switch( varType )
>     {
>         case VT_UI1:
>             return "VT_UI1";
>             break;

> Thanks......

Other Threads