在Delphi中,“ReturnAddress”是什么意思? [英] What does `at ReturnAddress` mean in Delphi?

查看:218
本文介绍了在Delphi中,“ReturnAddress”是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在浏览System.Zip(Delphi XE2)看看它是如何工作的时候,我发现这个功能:

  procedure VerifyWrite Stream:TStream; var Buffer; Count:Integer); 
begin
如果Stream.Write(缓冲区,计数)<>计数然后
在ReturnAddress处提高EZipException.CreateRes(@SZipErrorWrite);
结束

这是ReturnAddress 部分的困惑我



我不知道中的是一个有效的关键字(语法荧光笔似乎不认识它根据IDE,它被声明为 System.ReturnAddress ,但我只能发现它被声明为(asm)代码中的某个标签 procedure _HandleAnyException; 。系统单元已经被引用了。



所以我想知道的是这样的:


  1. 什么是 ReturnAddress

  2. code>提升异常。创建...在ReturnAddress do?

Bonuspoints如果你能给出一个真实世界的例子,说明这是一个有用的结构,或者你可以建议不要使用它。

解决方案

ReturnAddress 是完成 VerifyWrite 将返回的地址。



提升Exception.Create ...在ReturnAddress 表示当显示异常对话框时,它会将异常的地址指示为 ReturnAddress 。换句话说,异常消息将读取异常< whatever>在< ReturnAddress> ;:<异常消息> 中生成。



这是Delphi 7的帮助文件的摘录。它几乎和在线版本


要引发异常对象,请使用实例的例外
类与加注语句。例如,

  raise EMathError.Create; 

一般来说,加注语句的形式是

 提高对象在地址

其中对象和地址都是可选的;参见
重新提出异常。当指定地址时,
它可以是任何表达式,它计算为一个指针
类型,但通常是指向过程或函数的指针。
例如:

 在@MyFunction提升Exception.Create('Missing parameter'); 

使用此选项可以从栈中的早期点
引发异常实际发生错误的地方。


特别注意最后一句。关于在< address> 中使用是非常具体的。


While browsing System.Zip (Delphi XE2) to see how it works, I found this function:

procedure VerifyWrite(Stream: TStream; var Buffer; Count: Integer);
begin
  if Stream.Write(Buffer, Count) <> Count then
    raise EZipException.CreateRes(@SZipErrorWrite) at ReturnAddress;
end;

It's the at ReturnAddress part that sort of puzzles me.

I didn't know that at was a valid keyword (the syntax highlighter doesn't seem to recognise it either).

According to the IDE it's declared as System.ReturnAddress, but I can only find it declared as a label somewhere in the (asm) code of procedure _HandleAnyException;. The system unit is full of references to it though.

So what I would like to know is this:

  1. What is ReturnAddress?
  2. What exactly does Raise Exception.Create ... at ReturnAddress do?

Bonuspoints if you can give a real-world example of where this would be a useful construct, or if you can advice against using it.

解决方案

ReturnAddress is the address to which VerifyWrite would have returned when finished.

Raise Exception.Create... at ReturnAddress means that when the exception dialog is displayed, it would indicate the address of the exception as being at ReturnAddress. In other words, the exception message would read Exception <whatever> raised at <ReturnAddress>: <Exception Message>.

Here is an excerpt from the help file for Delphi 7. It's nearly the same as the online version.

To raise an exception object, use an instance of the exception class with a raise statement. For example,

raise EMathError.Create;

In general, the form of a raise statement is

raise object at address

where object and at address are both optional; see Re-raising exceptions. When an address is specified, it can be any expression that evaluates to a pointer type, but is usually a pointer to a procedure or function. For example:

raise Exception.Create('Missing parameter') at @MyFunction;

Use this option to raise the exception from an earlier point in the stack than the one where the error actually occurred.

Note the last sentence in particular. It's pretty specific about the use of at <address>.

这篇关于在Delphi中,“ReturnAddress”是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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