谢谢大家的回答,但都不符合我的要求,我已经自己解决了这个问题,这是我的代码,分数我回收了,希望大家见谅。
//使用 GetPropCount 可取得控件的的属性计数:
function GetPropCount(Instance: TPersistent): Integer;
var
Data: PTypeData;
begin
Data := GetTypeData(Instance.Classinfo);
Result := Data^.PropCount;
end;
//使用 GetPropName 可取得属性的名称:
function GetPropName(Instance: TPersistent; Index: Integer): string;
var
PropList: PPropList;
PropInfo: PPropInfo;
Data: PTypeData;
begin
Result := '';
Data := GetTypeData(Instance.Classinfo);
GetMem(PropList, Data^.PropCount * Sizeof(PPropInfo));
try
GetPropInfos(Instance.ClassInfo, PropList);
PropInfo := PropList^[Index];
Result := PropInfo^.Name;
finally
FreeMem(PropList, Data^.PropCount * Sizeof(PPropInfo));
end;
end;
procedure CloseForm(Form: TForm);
var
Index: Integer;
src: TPersistent;
SrcPropInfo: PPropInfo;
MyMethod: TMethod;
j: integer;
begin
with Form do
begin
for j := 0 to ComponentCount - 1 do
begin
src := TPersistent(Components[j]);
for Index := 0 to GetPropCount(Src) - 1 do
begin
SrcPropInfo := GetPropInfo(Src.ClassInfo, GetPropName(Src, Index));
if (srcPropInfo <> nil) and (SrcPropInfo^.PropType^.Kind = tkMethod)
then
begin
MyMethod := GetMethodProp(Src, SrcPropInfo);
if (Assigned(MyMethod.Data)) and (Assigned(MyMethod.Code)) then
begin
MyMethod.Data := nil;
MyMethod.Code := nil;
SetMethodProp(Src, SrcPropInfo, MyMethod);
end;
end;
end;
end;
end;
end;