gpt4 book ai didi

Delphi-如何在按钮单击时调用 ActionList?

转载 作者:行者123 更新时间:2023-12-02 00:00:34 24 4
gpt4 key购买 nike

我正在 Delphi XE8 中制作一个多设备应用程序,它使用 LiveBindings 来连接数据集。

FMX 有许多特定于 LB 的操作,包括 TFMXBindNavigateDelete。我正在尝试在按钮单击处理程序中使用它,如下所示:

按钮点击代码:

procedure TForm1.Button1Click(Sender: TObject);
begin
if cdsOrdersSTATUS.Value='READY' then
begin
ShowMessage('Your Order Is Already READY/PENDING!');
end
else
begin
TAction(ActionList1.Actions[0]).Execute; //Not working,why?
end;
end;

ActionList1 的操作中的第一个(也是唯一一个)项目是我的 FMXBindNavigateDelete1。

问题是,即使代码 TAction(ActionList1.Actions[0]).Execute 执行,当前数据集记录也没有被删除,所以显然TFMXBindNavigateDelete 的 Action 没有效果。为什么会这样,我怎样才能让它发挥作用?

图片。 Action 列表1:

ActionList

最佳答案

事实上,我认为这是一个很好的问题,不值得投反对票。

我可以重现你的问题。我在 FMX 表单上放置了两个按钮。我设置Button1 的 OnClick 到您的 Button1Click,Button2 的 ActionLiveBindingsBindNavigateDelete1

单击 Button2 会弹出标准的“删除记录?”确认并删除当前记录如果我回答"is",正如预期的那样。

但是,当单击 Button1 时,即使您的 else block 执行,也会出现“删除记录?”确认没有出现,因此该记录不可能被删除。

原因在代码中

function TCustomAction.Execute: Boolean;
begin
Result := False;
if Supported and not Suspended then
begin
Update;
if Enabled and AutoCheck then
if (not Checked) or (Checked and (GroupIndex = 0)) then
Checked := not Checked;
if Enabled then
Result := ((ActionList <> nil) and ActionList.ExecuteAction(Self)) or
((Application <> nil) and Application.ExecuteAction(Self)) or inherited Execute or
((Application <> nil) and Application.ActionExecuteTarget(Self));
end;
end;

Enabled 属性在调用期间似乎默认设置为 False更新,因此if Enabled then ...永远不会执行。我还没找到在调用 Update 期间将 Enabled 设置为 True 的方法。也许其他人知道如何做到这一点。

对于 Button2,执行会传递到 TComponent.ExecuteAction 并这是对 Action.ExecuteTarget(Self) 的调用,结果是记录删除例程正在执行。

因此,在我看来,你的问题似乎变成了如何调整代码,以便TComponent.ExecuteAction 被执行,也就是说,如何关联带有组件的 Action。答案相当明显。

所需要的就是这个

procedure TForm1.Button1Click(Sender: TObject);
begin
if cdsOrdersSTATUS.Value='READY' then
begin
ShowMessage('Your Order Is Already READY/PENDING!');
end
else
begin
Button1.ExecuteAction(LiveBindingsBindNavigateDelete1); // <- this works
//LiveBindingsBindNavigateDelete1.Execute; //Not working,why?
end;
end;

关于Delphi-如何在按钮单击时调用 ActionList?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42431336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com