translate pascal to c++

只谈情不闲聊 提交于 2019-12-08 06:35:31

问题


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++.


回答1:


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");
}



回答2:


Ok, looks like it is as simple as:

  if (ItemObject->Name == "I") {
     ShowMessage("Item Image clicked");
  }
  if (ItemObject->Name == "T") {
     ShowMessage("Item Text clicked");
  }
  if (ItemObject->Name == "A") {
     ShowMessage("Item Accessory clicked");
  }

This works on iOS as well as Win.



来源:https://stackoverflow.com/questions/49837687/translate-pascal-to-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!