Delphi如何确定哪个程序称为另一个程序? [英] Delphi how to determine which procedure called the another procedure?

查看:43
本文介绍了Delphi如何确定哪个程序称为另一个程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定谁调用了Showme程序?

How can i determine who called the Showme Procedure?

procedure Showme(str:string);
begin
  ShowMessage(str);
end;

procedure btnclick(sender:TObject);
begin
  Showme("test");
end;

procedure btn2click(sender:TObject);
begin
  Showme("test");
end;

编辑:混乱

Showme(654, '654'); // procedure name, string
Showme(654, '564');


推荐答案

没有内置方法可让一个过程知道哪个过程调用了它。如果您确实需要了解信息,则可以使用堆栈跟踪,但是这类数据实际上仅是调试所需的。对于实际执行而言,重要的是传递给例程的数据,而不是数据的来源。这是结构化编程的基本原则之一。如果两个不同的例程使用相同的数据调用相同的过程,则应将它们都视为相同。

There's no built-in way for one procedure to know which procedure called it. You can use stack tracing if you really need to know, but that sort of data is really only needed for debugging. For actual execution, what matters is the data that's passed to the routines, not where it came from. That's one of the basic principles of structured programming. If two different routines call the same procedure with the same data, it should treat them both the same.

您到底在做什么,才能知道区别?可能有一种更简单的方法来实现它。

What exactly are you doing where you need to be able to tell the difference? There might be a simpler way to accomplish it.

这篇关于Delphi如何确定哪个程序称为另一个程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆