不可能的任務? 能否動態列出所有 publish 了的 Method |
答題得分者是:william
|
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
|
william
版主 ![]() ![]() ![]() ![]() ![]() 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
Justmade
版主 ![]() ![]() ![]() ![]() ![]() ![]() 發表:94 回覆:1934 積分:2030 註冊:2003-03-12 發送簡訊給我 |
二個字 :
震驚天啊...procedure GetMethodList( FromClass: TClass; MethodList: TStrings ); overload; type PPointer = ^Pointer; PMethodRec = ^TMethodRec; TMethodRec = packed record <---居然知道儲存 Publish Method 的內部 Record 架構 wSize: Word; pCode: Pointer; sName: ShortString; end; var MethodTable: PChar; AClass: TClass; MethodRec: PMethodRec; wCount: Word; nMethod: integer; begin MethodList.Clear; AClass := FromClass; while AClass <> nil do begin //Get a pointer to the class's published method table MethodTable := PChar( Pointer( PChar( AClass ) vmtMethodTable )^ ); ↑ 要這樣取資料丫?? vmtMethodTable 又是甚麼怪獸誰會看system變數時知道丫 if MethodTable <> nil then begin //Get the count of the methods in the table Move( MethodTable^, wCount, 2 ); //Position the MethodRec pointer at the first method in the table //(skip over the 2-byte method count) MethodRec := PMethodRec( MethodTable 2 ); //Iterate through all the published methods of this class for nMethod := 0 to wCount - 1 do begin //Add the method name and address to the MethodList TStrings MethodList.AddObject( MethodRec.sName, MethodRec.pCode ); //Skip to the next method MethodRec := PMethodRec( PChar( MethodRec ) MethodRec.wSize ); end; end; //Get the ancestor (parent) class // The easy way: AClass := AClass.ClassParent; end; end;真的很可怕... |
william
版主 ![]() ![]() ![]() ![]() ![]() 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
I think the virtual method table has not been changed too much since its introduction back in TP 5.5 (or even eariler?). There should be quite a few documentation on it and you may find the book 'Delphi in a nutshell' interesting... It has a few pages on RTTI. For other questions.... I cannot "蛇" too long, so sorry
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |