How can I resolve "Ambiguity between TFont and Graphics::TFont" error?

I am trying to use the CustomDrawCell event for the TdxTreeListColumn column object.

When the method is added in .h file,

void __fastcall dxTreeListServiceCustomDrawCell(TObject *Sender,
TCanvas *ACanvas, TRect &ARect, TdxTreeListNode *ANode,
TdxTreeListColumn *AColumn, bool ASelected, bool AFocused,
bool ANewItemRow, AnsiString &AText, TColor &AColor,
TFont *AFont, TAlignment &AAlignment, bool &ADone);

When I try to compile this I get the following errors,

Error1 - Ambiguity between TRect and Windows:TRect
Error1 - Ambiguity between TFont and Graphics:TFont
Error1 - Ambiguity between TColor and Graphics:TColor

I am using C++ Builder 5.0 Professional


  • You get that error when two types in two different namespaces are named the same thing. Solve it by telling the compiler which one you mean, by writing the namespace explicitly in front of the type. Like Graphics::TFont.
  • I tried doing that, but doing that is not resolving the problem.
    When I try to save the file after making the change, the IDE throws an error saying the method for the event does not exist and do you want to remove the reference.

    Since this method declaration is generated by the IDE itself, i do not think we can modify the signature...
  • I have resolved the error related to ambiguity between TFont and Graphics::TFont and ambiguity between TColor and Graphics::TColor by using

    namespace Graphics {

    using Graphics::TFont;

    using Graphics::TColor;


    but how can I resolve the remaining error?
    the ambiguity between TRect and Windows::TRect?

  • well, if your class definition is outside any [b]namespace[/b], then you can not prefix it with the [b]namespace[/b] in this manner

    so, i suggest to tell the compiler that it is not part of any [b]namespace[/b] declaration by typing this explicitly
    ::TFont, ::TRect, ::TColor.

    ths should work fine, if these three classes definitions appear outside any [b]namespace[/b] ,since :: without any [b]namespace[/b] prefix (ie the unary version of this operator) means GLOBAL
    try to use it to distinguish between your local and global variables that carry the same name, or even static-member-functions and global functions that carry the same name.
    see ya
    Mohammad Nasim
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!