Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
943 views
in Technique[技术] by (71.8m points)

delphi - Obtaining address locations of an overload method

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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).

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;

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...