TAdvCardList: Delete Card in OnCardItemURLClick

Hello,


The following C++ code leads to an access violation

void __fastcall TForm2::AdvCardList1CardItemURLClick(TObject *Sender, int CardIndex,
          int ItemIndex, UnicodeString URL, bool &Default)
{
AdvCardList1->BeginUpdate();
AdvCardList1->Cards->Delete(CardIndex);
AdvCardList1->EndUpdate();
}

seems like the TCustomAdvCardList.click event hasn't finished.
usually, to solve this, i put the delete operation in a window-message:

PostMessage(Form2->Handle, WM_DELETE_CARD, CardIndex, 0);

MESSAGE __fastcall TForm2::HandleDeleteCard(TMessage &Msg)
{
AdvCardList1->Cards->Delete(Msg.WParam);
}

but it doesn't help in this case either, the access violation then happens later at TCustomAdvCardList.ItemAtXY

How can I prevent this?

Call Abort() at the end of the event handler.


Was tested here with:

procedure TForm1.AdvCardList1CardItemURLClick(Sender: TObject; CardIndex,
  ItemIndex: Integer; URL: string; var Default: Boolean);
begin
  ShowMessage(url);
  AdvCardList1.BeginUpdate;
  AdvCardList1.Cards.Delete(CardIndex);
  AdvCardList1.EndUpdate;
  Abort;
end;

and this worked without issue.

Thanks, that worked for me. This interrupts the selection of the card after clicking on the link, but anyway i don't expect that selection necessarily.