【发布时间】:2021-08-03 00:31:45
【问题描述】:
我正在创建一个显示帐单号码的应用程序,就像您在麦当劳看到的那样。 POS 系统将账单号码发送到我的应用程序,这些号码显示在名为“ListBoxPrep”的 TListBox 中。然后,当 POS 系统向我的应用发送要删除的账单编号时,我的应用会从“ListBoxPrep”中删除它并将其添加到“ListBoxReady”。 POS 和我的应用程序之间的每次通信都是通过 TCP 连接完成的,我对此没有任何问题。
我面临的问题是,即使在通过“pItem->Free();”删除它之后,我仍然看到该数字仍保留在“ListBoxPrep”中。 “pItem”是TListBoxItem 的指针。我希望我的应用程序从 POS 接收到“删除信号”后数字消失,尤其是在没有用户交互(例如单击面板等)的情况下。我想使用 TTimer,但我不知道如何使“ListBoxPrep”刷新本身。你有什么想法吗?任何建议将不胜感激。我正在使用 RAD Studio 10.4。
在我的应用收到来自 POS 的“删除信号”后,我仍然看到右侧的数字。他们应该消失。
void __fastcall TForm1::IdTCPServerExecute(TIdContext *AContext)
{
//We receive data: POS --> Screen(PC)
String sentDataFromPOS = AContext->Connection->Socket->ReadLn();
if(sentDataFromPOS .IsEmpty())
{
ShowMessage("Data sent from POS is empty!");
return;
}
// 1. Find an order number to move to the right (prep -> ready)
int indexOrderToRemove = ListBoxPrep->Items->IndexOf(sentDataFromPOS);
// 2. Add the order number to the "Ready list"
addNumberToReady(sentDataFromPOS);
// 3. Remove the order from the "Prep list"
ListBoxPrep->BeginUpdate();
TListBoxItem* pItem = ListBoxPrep->ItemByIndex(indexOrderToRemove);
pItem->Free(); // HERE I have a problem
// test: To refresh the screen
LayoutLeft->Visible = false;
LayoutLeft->Visible = true;
/*
ListBoxPrep->Enabled = false;
ListBoxPrep->Visible = false;
ListBoxPrep->Enabled = true;
ListBoxPrep->Visible = true;
ListBoxPrep->Repaint();
*/
ListBoxPrep->EndUpdate();
}
【问题讨论】:
-
sentDataFromKitchen与sentDataFromPOS有什么关系? -
哦,实际上
sentDataFromKitchen是sentDataFromPOS。我错误地输入了sentDataFromKitchen,对不起。我已经编辑了代码。
标签: firemonkey c++builder rad-studio