Search code examples
firemonkeyc++builder-10.2-tokyo

translate pascal to c++


The following code runs in the ItemClickEx event of a firemonkey ListView. I want to know how to do this in C++.

procedure TfrmCategory.lstListCategoryItemClickEx(const Sender: TObject; 
                         ItemIndex: Integer; const LocalClickPos: TPointF;
    const ItemObject: TListItemObject);

begin
    if ItemObject is TListItemAccessory then
     begin
      ShowMessage('Acessory clicked');
     end;

end;

Source: link here.

I don't know how to do the "if ItemObject is TListItemAccessory" in c++.


Solution

  • The C++ equivalent to Delphi's is operator is dynamic_cast, eg:

    void __fastcall  TfrmCategory::lstListCategoryItemClickEx(const TObject *Sender,
        int ItemIndex, const TPointF &LocalClickPos, const TListItemObject* ItemObject)
    {
        if (dynamic_cast<const TListItemAccessory*>(ItemObject))
            ShowMessage(L"Acessory clicked");
    }