Thanks by u answer. Very good point, but i won't use rtti.
I want register the address of a method on TypeInfo Manager (created
by us).
When I need call this method I will to use this addres but some
methods has parameters and I need pass this one. I cannot create a
callback procedure to each method that i will call, then I need a
routine to call a method and pass parameters dynamically.
Today I do this with Getters and Setters, but i need something generic.
Sample to a simple Getter:
with RegisterNewType(IPersonalMoney, 'PersonalMoney',
TPersonalMoney, IInfraObject, GetTypeInfo(IInfraObject)) do
begin
AddMember('AccountOwner', TInfraString,
IInfraString, IInfraString,
@TPersonalMoney.GetAccountOwnerInfraType);
AddMember('Accounts', TAccounts, IAccounts, IInfraList,
@TPersonalMoney.GetAccountsInfraType);
end;
IInfraTypeInfo = interface(IInfraElement)
['{9312E672-B45C-4E65-B755-68142E57E279}']
function AddMember(const MemberName: string; InfraClass: TClass;
const ValueTypeIntf, FamilyType: TGUID;
Getter: Pointer = nil; Setter: Pointer = nil): IInfraTypeInfo;
function GetGetterMethod: Pointer;
procedure SetSetterMethod(Value: Pointer);
...
property GetterMethod: Pointer read GetGetterMethod write
SetGetterMethod;
property SetterMethod: Pointer read GetSetterMethod write
SetSetterMethod;
end;
// if we get a generic call this callbacks can be removed too
TGetter = function : IInterface of object;
TSetter = procedure (Value: IInterface) of object;
procedure TInfraTypeRegister.SetFeature(const ObjIntf: IInfraElement;
const TypeInfo: IInfraTypeInfo; const Value: IInterface);
var
Method: TMethod;
begin
with Method do
begin
Data := Pointer((ObjIntf as IInfraInstance).GetInstance);
Code := TypeInfo.SetterMethod;
if Assigned(Code) then
TSetter(Method)(Value) // <<<<<<<<< I want call here something
// like:
// CallMethod(Method, Parameters)
else
Raise Exception.Create('Feature''''s Getter method not found!');
end;
end;
function TInfraTypeRegister.GetFeature(const ObjIntf: IInfraElement;
const TypeInfo: IInfraTypeInfo): IInterface;
var
Method: TMethod;
Execute: TGetter;
NewRes: IInfraElement;
begin
with Method do
begin
Data := Pointer((ObjIntf as IInfraInstance).GetInstance);
Code := TypeInfo.GetterMethod;
if Assigned(Code) then
begin
Execute := TGetter(Method);
Result := Execute; // <<<<<< and here too:
// Result := CallMethod(Method, Parameters)
Supports(Result, TypeInfo.TypeId, NewRes);
if Assigned(Result) then
Assert(Assigned(NewRes), 'Class '''+
TypeInfo.ImplClass.ClassName +''' doesn''t implement the interface ('+
GUIDToString(TypeInfo.TypeId) +') defined in the typeinfo '''+
TypeInfo.Name +'''');
Result := NewRes;
end else
Raise Exception.Create('Feature''''s Getter method not found!');
end;
end;
I need CallMethod to any object's method (private, public, protected,
etc...)
------------------------ Yahoo! Groups Sponsor --------------------~-->
Most low income homes are not online. Make a difference this holiday season!
http://us.click.yahoo.com/5UeCyC/BWHMAA/TtwFAA/i7folB/TM
--------------------------------------------------------------------~->
-----------------------------------------------------
Home page: http://groups.yahoo.com/group/delphi-en/
To unsubscribe: [EMAIL PROTECTED]
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/delphi-en/
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/