gpt4 book ai didi

delphi - `at ReturnAddress`在Delphi中是什么意思?

转载 作者:行者123 更新时间:2023-12-03 14:33:48 25 4
gpt4 key购买 nike

在浏览System.Zip(Delphi XE2)以查看其工作原理时,我发现了这个函数:

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

at ReturnAddress 部分让我感到困惑。

我不知道 at 是一个有效的关键字(语法荧光笔似乎也无法识别它)。

根据 IDE,它被声明为 System.ReturnAddress,但我只能在 procedure _HandleAnyException; 的(asm)代码中的某个位置找到它被声明为标签。不过,系统单元充满了对它的引用。

所以我想知道的是:

  1. 什么是ReturnAddress
  2. Raise Exception.Create ... at ReturnAddress 到底做了什么?

如果您能给出一个现实世界的示例来说明这将是一个有用的构造,或者您可以建议不要使用它,那就加分了。

最佳答案

ReturnAddressVerifyWrite 的地址完成后就会返回。

Raise Exception.Create... at ReturnAddress表示当显示异常对话框时,它将指示异常的地址为 ReturnAddress 。换句话说,异常消息将显示为 Exception <whatever> raised at <ReturnAddress>: <Exception Message>

这里是 Delphi 7 帮助文件的摘录。它与 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.

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

关于delphi - `at ReturnAddress`在Delphi中是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8950513/

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