有没有办法在知道一个字符串的情况下,在同一程序里找到以这个字符串命名的函数地址?就像得到DLL里函数地址的WINAPI:GetProcAddress一样的?
解决方案 »
- 300分求解,这个问题困扰我很久了!!!!我发了3个贴子,每个100分!~~~~求解!!~~~~~~~~
- 如何取DateTimePicker的时间写入Access数据库
- 帮个忙
- 很简单的问题,Delphi不能实现吗?????????
- 求公历和农历转换的算法
- 三层结构中dCom的连接
- 高手请进!解决马上给分,在线等待!!!
- cxgrid 中 一个字段列的 Properties 设置为LookupComboBox时,怎么在 LookupComboBox弹出下拉框时,在LookupComboBox 拉框里面 放入一个panel 控件
- 如何改变TTreeView的Hint?
- 知道了*.dfm 和*.pas文件可不可以不用再去搞窗体了??
- DBGRID导出问题
- delphi中listview如何设置为透明!
但如果是非导出函数, 编译后的结果并不包含函数名称信息, 则无法单纯通过exe或dll文件获得函数名称对应的地址信息
但如果你编译时生成了map文件, 则使用map文件可以知道函数名称对应的地址信息注: Delphi中Project Options对话框的Linker页可以设定Map File选项
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
published
procedure test;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
type
padd=procedure;
procedure TForm1.Test;
begin
ShowMessage('ok');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
p:padd;
t:pointer;
begin
t:=MethodAddress('Test');
if t<>nil then
padd(t);
end;end.如果是其它函数,一般情况下是不可能得到它的地址的,因为delph是编译程序,一般情况下,函数编译后,名字不再写入exe中,所以无法得到
当然,如果函数是导出的,可通过GetProcAddress得到它的地址:
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
published
procedure test;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
type
padd=procedure;
procedure testt;
begin
ShowMessage('ok1');
end;
procedure TForm1.Test;
begin
ShowMessage('ok');
end;
procedure TForm1.Button1Click(Sender: TObject);
var t:pointer;
begin
t:=MethodAddress('Test');
if t<>nil then
padd(t);
t:= GetProcAddress( MainInstance,'testt');
if t<>nil then
padd(t);
end;
exports testt;
end.