获取重载方法的地址位置

编程入门 行业动态 更新时间:2024-10-11 01:15:05
本文介绍了获取重载方法的地址位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何获取重载的函数/过程/方法的所有地址位置?

How do I get all the address locations for functions/procedures/methods that is overloaded?

例如,Dialogs.MessageDlgPosHelp重载有两个不同版本的 - 一个没有默认按钮,一个没有。如何获取这两个函数的地址位置?

For example, Dialogs.MessageDlgPosHelp is overloaded having two different versions of it - one without a default button and one with. How would I obtain the address locations for the two functions?

推荐答案

根据 这个线程 以及什么 Thomas Mueller 指出,您可能会定义与要获取的地址(每个重载)的方法相同的签名类型。如果然后声明这些类型的变量并给它们分配方法指针,那么您将确保编译器为已知变量类型选择正确的重载,此外,如果不在代码中的任何位置使用它,它将不会忽略它们(有些重载可能无法在二进制文件中链接)。

Based on this thread and what Thomas Mueller pointed there, you might define types with the same signatures as methods whose addresses you want to obtain (for each overload). If you then declare the variables of those types and assign method pointers to them you will make sure that compiler chooses the right overload to your known variable type and moreover that it won't ignore them if they wouldn't be used anywhere in the code (some overloads might not get linked in your binary).

所以根据他的想法,它可能会寻找 MessageDlgPosHelp 功能重载如下:

So based on his idea it might looks for the MessageDlgPosHelp function overloads like this:

type TMessageDlgPosHelp1 = function(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; TMessageDlgPosHelp2 = function(const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string; DefaultButton: TMsgDlgBtn): Integer; procedure TForm1.Button1Click(Sender: TObject); var MessageDlgPosHelp1: TMessageDlgPosHelp1; MessageDlgPosHelp2: TMessageDlgPosHelp2; begin MessageDlgPosHelp1 := MessageDlgPosHelp; MessageDlgPosHelp2 := MessageDlgPosHelp; ShowMessage(Format('%p; %p', [@MessageDlgPosHelp1, @MessageDlgPosHelp2])); end;

更多推荐

获取重载方法的地址位置

本文发布于:2023-11-28 08:56:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1641754.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:位置   地址   方法

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!