Type Ambiguities
Problem |
Some of the components of SDL have type definitions which are syntactically equal to each other. For organizational reasons they are declared separately in each unit. However, this approach may result in ambigous type declarations, if two or more of these components are used within the same program. The compiler generates the following error message:
Delphi: Incompatible Types
C++Builder: Ambiguity between 'xxx::ttt' and 'zzz::ttt' |
Solution |
If such a problem occurs, the user has to explicitely specify the unit, or the C++ name space of the type declaration by using the name of the unit preceding the actual identifier. The unit name is separated by a dot (or two colons in case of C++) from the identifier.
|
Example |
Suppose you are using the component RChart and a popup menu under Delphi 5 or higher. The component RChart offers a property MouseAction which may be set to maNone to turn it off. The same is true for the property MenuAnimation of a popup menu. In order to assign the value maNone to the properties MouseAction and MenuAnimation you have to specify the name space (= the name of the unit):
in Delphi:
MyRChart1.MouseAction := Sdlbase.maNone;
MyPopupMenu1.MenuAnimation := [Menu.maNone];
or the same in C++:
MyRChart1->MouseAction = Sdlbase::maNone;
MyPopupMenu1->MenuAnimation = [Menu::maNone];
Hint: |
Please note that from release 8.5 upwards, all units of the SDL Suite have inserted the prefix SDL_ to avoid name conflicts. So the appropriate statements would read
in Delphi:
MyRChart1.MouseAction := Sdl_sdlbase.maNone;
MyPopupMenu1.MenuAnimation := [Menu.maNone];
or the same in C++:
MyRChart1->MouseAction = Sdl_sdlbase::maNone;
MyPopupMenu1->MenuAnimation = [Menu::maNone];
|
|
Other type ambiguities:
[bcc32 Error] mainfrm.cpp(131): E2015 Ambiguity between 'Sdl_sdlbase::TDirection' and 'System::Types::TDirection'
Sdl_sdlbase::TDirection --> System::Types::TDirection
Sdl_vector::TVector
Sdl_matrix::TMatrix
|