获取重载方法的地址位置 [英] Obtaining address locations of an overload method

查看:130
本文介绍了获取重载方法的地址位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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;

这篇关于获取重载方法的地址位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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