Board index » delphi » How call register methods

How call register methods


2005-12-17 01:58:51 AM
delphi80
How can I call register methods with paraemters dinamically?
Anyone has some procedure to this?
thanks
 
 

Re:How call register methods

Best thing to do is take a look at RemObjects Pascal Script for Delphi.
Their you will find everything you need to know about calling CDecl,
Register, Pascal, Stack, and Other types. Be warned; This is a very complex
thing to play with and is not for anyone that doesn't know (and like)
assembly. Personally I have been working on some generic objects and routines
for almost a year now (in my little spare time, prolly about 40 hrs real
time) to do this type of thing.
Course thats saying that you mean Reigster as in calling method and not
register as in Register a new control into the Delphi IDE :).
- Jeremy
"Marcos" <XXXX@XXXXX.COM>writes
Quote
How can I call register methods with paraemters dinamically?
Anyone has some procedure to this?

thanks
 

Re:How call register methods

At 18:58:51, 16.12.2005, Marcos writes:
Quote
How can I call register methods with paraemters dinamically?
Anyone has some procedure to this?
What do you exactly mean with calling them dynamically? If you mean you
don't know the exact name or number of parameters beforehand, you will have
to resort to some tricks, like assembler, or like declaring a function
pointer for the combinations you might meet.
--
Rudy.Velthuis {TeamB} velthuis.homepage.t-online.de/
"Life would be so much easier if we could just see the source code."
-- unknown
 

Re:How call register methods

Quote
What do you exactly mean with calling them dynamically? If you mean you
don't know the exact name or number of parameters beforehand, you will have
to resort to some tricks, like assembler, or like declaring a function
pointer for the combinations you might meet.
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...)
 

Re:How call register methods

Unfortunately you can not do this without registering the methods some how to
your caller with regards to its specific VMT Address. You will also have to
make sure that you have the EXACT number and type of Params correct. As I
said before take a look at Rem-Objects "Pascal Script for Delphi" available
on
www.remobjects.com/page.asp
Once you download it check out the Rem-Objects NG's
(news://news.remobjects.com/remobjects.public.pascalscript) for a post from
me about calling a method via Assembler.
To quote Carlo from the NG:
"InnerfuseCall is where you want to look. that is the function that
invokes them. However you need the pointers for the methods you call.
PascalScript doesn't use Methodaddress (for good reason, as you found
out, it only does published methods) so you need to maintain a list of them.
--
Carlo Kok
RemObjects Software"
Thats about the extent of what you need to know, it will tell you everything
you need to know (providing you know assembly, if not your hosed).
- Jeremy
"Marcos" <XXXX@XXXXX.COM>writes
Quote
>What do you exactly mean with calling them dynamically? If you mean you
>don't know the exact name or number of parameters beforehand, you will have
>to resort to some tricks, like assembler, or like declaring a function
>pointer for the combinations you might meet.

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...)