bbscom侠!你的问题的详述是看不太懂!从标题获取事件的声明部分知道
savetime侠的这个函数GetMethodTypeInfo能完成你想要的功能!我的测试代码的结果
---------------------------------
Method Name: TKeyPressEvent
Method Kind: mkProcedure
Params Count: 2
Params List:
[] Sender: TObject
[ pfVar] Key: Char
能完成功能!!!!!
-----------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,TypInfo;
type
TForm2 = class(TForm)
Edit1: TEdit;
procedure FormCreate(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject;
var Key: Char);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.Edit1KeyPress(Sender: TObject;
var Key: Char);
begin
end;
procedure GetMethodTypeInfo(ATypeInfo: PTypeInfo;
AStrings: TStrings);
type
PParamData = ^TParamData;
TParamData = record // 函数参数的数据结构
Flags: TParamFlags;
// 参数传递规则
ParamName: ShortString;
// 参数的名称
TypeName: ShortString;
// 参数的类型名称
end;
function GetParamFlagsName(AParamFlags: TParamFlags): string;
var
I: Integer;
begin
Result := '';
for I := Integer(pfVar) to Integer(pfOut)do
begin
if I = Integer(pfAddress) then
Continue;
if TParamFlag(I) in AParamFlags then
Result := Result + ' ' + GetEnumName(TypeInfo(TParamFlag), I);
end;
end;
var
MethodTypeData: PTypeData;
ParamData: PParamData;
TypeStr: PShortString;
I: Integer;
begin
MethodTypeData := GetTypeData(ATypeInfo);
AStrings.Add('---------------------------------');
AStrings.Add('Method Name: ' + ATypeInfo^.Name);
AStrings.Add('Method Kind: ' + GetEnumName(TypeInfo(TMethodKind),
Integer(MethodTypeData^.MethodKind)));
AStrings.Add('Params Count: '+ IntToStr(MethodTypeData^.ParamCount));
AStrings.Add('Params List:');
ParamData := PParamData(@MethodTypeData^.ParamList);
for I := 1 to MethodTypeData^.ParamCountdo
begin
TypeStr := Pointer(Integer(@ParamData^.ParamName) +
Length(ParamData^.ParamName) + 1);
AStrings.Add(Format(' [%s] %s: %s',[GetParamFlagsName(ParamData^.Flags),
ParamData^.ParamName, TypeStr^]));
ParamData := PParamData(Integer(ParamData) + SizeOf(TParamFlags) +
Length(ParamData^.ParamName) + Length(TypeStr^) + 2);
end;
if MethodTypeData^.MethodKind = mkFunction then
AStrings.Add('Result Value: ' + PShortString(ParamData)^);
end;
procedure TForm2.FormCreate(Sender: TObject);
var
M:TMethod;
pinfo
PropInfo;
s:TStringList;
begin
s:=TStringList.Create;
GetMethodTypeInfo(TypeInfo(TKeyPressEvent),s);
s.SaveToFile('c:/a.txt');
end;
end.