Search code examples
c++dbexpress

Concatenating TFields values


I have a calculated fields in a client dataset named full address of type Memo.

I want to concatenate address fields, something like this:

    TField* f = customersCDS->FieldByName("full_address");
    if(f)
    {
        f->Value = customersCDS->FieldByName("address_line1")->Value;
        f->Value += "\n";
        f->Value += customersCDS->FieldByName("address_line2")->Value;
        ..
    }

However, the above don't work. I get compiler error:

E2015 Ambiguity between '_fastcall operator Variant::float() const'   and '_fastcall operator Variant::double() const'

In the end, I want to bind the calculated field with a TMemo, showing the full address on multiple lines.


Solution

  • TField::Value is a property. You cannot use compound assignment operators, like +=, with properties. You have to use + and = separately, eg:

    TField* f = customersCDS->FieldByName("full_address");
    if (f)
    {
        f->Value = customersCDS->FieldByName("address_line1")->Value;
        f->Value = f->Value + String("\n");
        f->Value = f->Value + customersCDS->FieldByName("address_line2")->Value;
        ..
    }
    

    In which case, you are better off using a variable instead:

    TField* f = customersCDS->FieldByName("full_address");
    if (f)
    {
        String s = customersCDS->FieldByName("address_line1")->Value;
        s += "\n";
        s += customersCDS->FieldByName("address_line2")->Value;
        //...
        f->Value = s;
    }