Delphi 根據(jù)字符串找到函數(shù)并執(zhí)行的實例
Delphi 根據(jù)字符串找到函數(shù)并執(zhí)行的實例
關鍵字:MethodAddress:取得方法的地址,這個方法需要是published的。
實例代碼:
unit Unit1; 
 
interface 
 
uses 
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
 Dialogs, StdCtrls; 
 
type 
 
 TShowInfo = procedure(info:string) of object;  //聲明一個procedure類型,參數(shù)和ShowInfo一致 
 
 TForm1 = class(TForm) 
  Button1: TButton; 
  procedure Button1Click(Sender: TObject); 
 private 
  { Private declarations } 
 public 
  { Public declarations } 
 
 published 
  procedure ShowInfo(info:string); 
 end; 
 
var 
 Form1: TForm1; 
 
implementation 
 
{$R *.dfm} 
 
{ TForm1 } 
 
procedure TForm1.ShowInfo(info: string); 
begin 
 ShowMessage(info); 
end; 
 
procedure TForm1.Button1Click(Sender: TObject); 
var 
 s:TShowInfo; 
begin 
 @s := MethodAddress('ShowInfo');    //取得ShowInfo的地址 
 if @s <> nil then           //如果不為空 
 begin 
  s('中華人民共和國');         //執(zhí)行 
 end; 
end; 
 
end. 
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
欄 目:Delphi
下一篇:Windows API GetLastError()函數(shù)返回值含義解釋
本文標題:Delphi 根據(jù)字符串找到函數(shù)并執(zhí)行的實例
本文地址:http://www.jygsgssxh.com/a1/Delphi/8597.html
您可能感興趣的文章
- 01-10在Delphi實現(xiàn)在數(shù)據(jù)庫中存取圖像的圖文演示無錯
 - 01-10delphi建立、讀取、存貯INI文件的方法《三》
 - 01-10Delphi Command模式
 - 01-10delphi 正弦曲線圖
 - 01-10delphi建立、讀取、存貯INI文件的方法《二》
 - 01-10插件管理框架 for Delphi(二)
 - 01-10插件管理框架 for Delphi(一)
 - 01-10Delphi中判斷文件是否為文本文件的函數(shù)
 - 01-10delphi中一個值得大家來考慮的DLL問題
 - 01-10初探Delphi中的插件編程
 


閱讀排行
本欄相關
- 01-10在Delphi實現(xiàn)在數(shù)據(jù)庫中存取圖像的圖
 - 01-10delphi建立、讀取、存貯INI文件的方法
 - 01-10delphi 正弦曲線圖
 - 01-10Delphi Command模式
 - 01-10delphi建立、讀取、存貯INI文件的方法
 - 01-10插件管理框架 for Delphi(二)
 - 01-10插件管理框架 for Delphi(一)
 - 01-10Delphi中判斷文件是否為文本文件的函
 - 01-10delphi中一個值得大家來考慮的DLL問題
 - 01-10初探Delphi中的插件編程
 
隨機閱讀
- 04-02jquery與jsp,用jquery
 - 01-10delphi制作wav文件的方法
 - 08-05織夢dedecms什么時候用欄目交叉功能?
 - 08-05DEDE織夢data目錄下的sessions文件夾有什
 - 08-05dedecms(織夢)副欄目數(shù)量限制代碼修改
 - 01-10C#中split用法實例總結
 - 01-11Mac OSX 打開原生自帶讀寫NTFS功能(圖文
 - 01-11ajax實現(xiàn)頁面的局部加載
 - 01-10使用C語言求解撲克牌的順子及n個骰子
 - 01-10SublimeText編譯C開發(fā)環(huán)境設置
 


