简体   繁体   English

在 Delphi 中,如何从 asm 语句内部调用私有属性读取函数

[英]In Delphi, how do you call a private property read function from inside an asm statement

This line of Pascal code:这行帕斯卡代码:

gh := GCanvas.Handle

(where GCanvas is a variable of type TCanvas) (其中 GCanvas 是 TCanvas 类型的变量)

converts to this in assembly language (as viewed in the CPU window):在汇编语言中转换为这个(在 CPU 窗口中查看):

mov eax,[GCanvas]
call TCanvas.GetHandle
mov [gh],eax

GetHandle is the private function that returns the value of FHandle defined in Graphics.pas GetHandle 是返回 Graphics.pas 中定义的 FHandle 值的私有函数

How can I access the TCanvas Handle property inside an asm statement?如何在 asm 语句中访问 TCanvas Handle 属性? I tried the call as above but the compiler returns "Undeclared identifier 'GetHandle'" So how do you access properties where the value is returned by a function call?我尝试了上述调用,但编译器返回“未声明的标识符‘GetHandle’” 那么如何访问由函数调用返回值的属性?

Any help, please?请问有什么帮助吗?

If the property accessor method is PRIVATE then the simple answer is: You can't.如果属性访问器方法是 PRIVATE,那么简单的答案是:你不能。 The compiler simply doesn't know that symbol at that point in your code.编译器根本不知道代码中那个点的符号。 Even from Pascal, you can't, except by going via RTTI and that is probably too cumbersome to do from assembly.即使从 Pascal,你也不能,除非通过 RTTI,这可能太麻烦了,无法从组装中完成。

The way to do it is to provide a "gateway" function that calls on to the property (which in turn calls the private function):这样做的方法是提供一个调用属性的“网关”函数(反过来调用私有函数):

FUNCTION GetHandle(C : TCanvas) : HDC; Register;  // Must be a Global function //
  BEGIN
    Result:=C.Handle
  END;

and then from your assembly code:然后从你的汇编代码:

VAR GCanvas : TCanvas;
VAR gh : THandle;

ASM
        MOV     EAX,GCanvas
        CALL    GetHandle
        MOV     [gh],EAX
END

If you make the GetHandle function a method of a class, you need to pass "Self" (the instance of the class) in EDX to the function as well.如果将 GetHandle 函数设为类的方法,则还需要将 EDX 中的“Self”(类的实例)传递给该函数。

I also found this this morning - if I end the asm statement to go back to Pascal and use the line我今天早上也发现了这个 - 如果我结束 asm 语句回到 Pascal 并使用该行

GCanvas.Handle;

this calls the GetHandle function and the result is left in eax - then enter a new asm statement and eax can be stored or pushed as needed.这将调用GetHandle函数并将结果留在 eax 中——然后输入一个新的 asm 语句,eax 可以根据需要进行存储或推送。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM