问题
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