Knowledge Base



KB10922 - C++Builder gives a const compiling error on Legend.OnLayerSelect event.

In C++Builder XE6, compiling event code like

  void __fastcall TfrmGUI_RGIS::LegendLayerSelect(const TObject *_sender, const TGIS_LayerAbstract *_layer)
  {
  ShowMessage(_layer->Name);
  }
causes a compiling error.

The solution is to use a casting (a canonical way):
  ShowMessage(const_cast<TGIS_LayerAbstract*>(_layer)->Name);

Or use a non-canonical way, which surprisingly also works:

  ShowMessage(((TGIS_LayerAbstract *)_layer)->Name);

While this issue was found on XE6, it is probably common for all non CLANG based compilers.

 

Created: August 01, 2016, Modified: August 01, 2016