delphi - 如何从内部(重新)调用函数,而不将原始调用返回给发件人
问题描述
这是我试图解释的一个例子:
Var
NotDone:Boolean=False;
Function MyTestFunction:Boolean;
begin
if NotDone<>True then
begin
NotDone:=True;
MyTestFunction();
end else
begin
Result:=True;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
NotDone:=False;
if mMyTestFunction=True then
begin
ShowMessage('Returned: True');
end else
begin
ShowMessage('Returned: False');
end;
end;
所以我基本上想调用我的函数,并在某些情况下从内部“调用”,而不是主调用(button1 click 中的代码表达式)从第一次调用中获取结果,然后处理 Second 并返回它。
如您所见,我本来希望它返回true,但它返回false。
- 我怎样才能实现我的目标和/或最佳实践/解决方法是什么,而不是编写函数的副本。
解决方案
如您所见,我本来希望它返回true,但它返回false。
实际上,返回值是未定义的,就像在“NotDone<>True”的情况下,你永远不会为调用的结果分配任何值......
如果我理解正确,这不是吗:
Function MyTestFunction:Boolean;
begin
if NotDone<>True then
begin
NotDone:=True;
Result:=MyTestFunction(); // Return the value from second invokation
end else
begin
Result:=True;
end;
end;
推荐阅读
- revit-api - REVIT 将地板草图转移到家庭中的空隙挤压
- c++ - 静态 std::initializer_list 的初始化导致 VS2015 更新 3 警告 C4592
- swift - 是否需要在单例类中使用弱引用?
- c# - Xamarin.Forms,选择器,显示 SelectedItem 的问题
- c# - C#/MonoGame - 当我卸载我的游戏关卡时销毁内存中的大对象
- javascript - 如何从 jQuery 中的其他 html 文件中读取数组/数据并创建动态表(PLC 网络服务器)
- ios - UIButton 在第一次运行时工作正常,但在模拟器上第二次运行时不起作用
- html - 如何按字母顺序对无序列表进行排序?
- sql - SQL - 对于每个 ID,其他列中的值应重复
- powershell - docker容器内powershell中的端口绑定