Board index » delphi » How call register methods
Marcos
![]() Delphi Developer |
Marcos
![]() Delphi Developer |
How call register methods2005-12-17 01:58:51 AM delphi80 How can I call register methods with paraemters dinamically? Anyone has some procedure to this? thanks |
Jeremy Darling
![]() Delphi Developer |
2005-12-17 03:26:32 AM
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 QuoteHow can I call register methods with paraemters dinamically? |
Rudy Velthuis [TeamB]
![]() Delphi Developer |
2005-12-17 05:18:05 AM
Re:How call register methods
At 18:58:51, 16.12.2005, Marcos writes:
QuoteHow can I call register methods with paraemters dinamically? 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 |
Marcos
![]() Delphi Developer |
2005-12-17 09:08:36 PM
Re:How call register methodsQuoteWhat do you exactly mean with calling them dynamically? If you mean you 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...) |
Jeremy Darling
![]() Delphi Developer |
2005-12-19 10:25:36 PM
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 |