Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Getting Address Property

115 views
Skip to first unread message

Fernando Barbosa

unread,
May 24, 1999, 3:00:00 AM5/24/99
to

Is there something like "MethodAddress" that can get the address of a
property (not of a method)??

I have to get the property pointer and assign it to a variable. Is this
possible?

Kurt Barthelmess (TeamB)

unread,
May 25, 1999, 3:00:00 AM5/25/99
to
Fernando -

No. The problem is that there may not be such a thing. You can define
a property that has read and/or write methods, but has no underlying
variable. As an example, look at this "get" method:

function GetMyProp: Integer;
begin
GetMyProp := A + B;
end;

Good luck.

Kurt

Fernando Barbosa

unread,
May 25, 1999, 3:00:00 AM5/25/99
to

Kurt Barthelmess (TeamB) <71333...@compuserve.com> escreveu na mensagem
<3749fdce...@forums.borland.com>...
>Fernando -

> > I have to get the property pointer and assign it to a variable. Is
this
> > possible?
>
>No. The problem is that there may not be such a thing. You can define
>a property that has read and/or write methods, but has no underlying
>variable.
>
>Kurt

Ok, thanks Kurt.

I have one more question...

Can I invoke a method knowing only its name??
The situation is: I have a ClassName and a MethodName in my DB, can I
invoke this MethodName. I did it using Java, but couldn't find how to do it
with Delphi, once I think the result of "FieldAddress" doesn't point to the
method by itself. Or I'm wrong?

Peter Below (TeamB)

unread,
May 25, 1999, 3:00:00 AM5/25/99
to
In article <7ieimm$t3...@forums.borland.com>, Fernando Barbosa wrote:
> The situation is: I have a ClassName and a MethodName in my DB, can I
> invoke this MethodName.
>

You can get the address of a *published* method (see MethodAddress),
but you need an object (an instance of a class) to apply the method to,
not simply a class. Having both you can construct a method pointer of
an appropriate type, e.g.


var
m: TNotifyEvent;
begin
TMethod(m).data := someObject;
TMethod(m).code := someObject.methodAddress( methodname );
If assigned(m) then
m( somesender );


Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!


Thomas Quester

unread,
May 25, 1999, 3:00:00 AM5/25/99
to
> Can I invoke a method knowing only its name??
> The situation is: I have a ClassName and a MethodName in my DB, can I
>invoke this MethodName. I did it using Java, but couldn't find how to do it
>with Delphi, once I think the result of "FieldAddress" doesn't point to the
>method by itself. Or I'm wrong?

Yes, you can, simply pass the class pointer as the first parameter.

Yes, you can. Suppose the method is called foo with no parametes and c
is a pointer to the class.

Now you can do

type
TFooProc = procedure(obj : TObject);

procedure CallIt(c : TPersistant; name : string);
var procptr : TFooProc;
begin
procPtr := c.MethodAddress(name);
if procPtr <> NIL then procPtr(c);
end;

( I am not shure, if MethodAddress was is available in TPersistent, I
did it with TComponent-descendent).

If you have a variable count of parameters, you have to go a bit
further: Create an array of byte and write the some assembler code to
that array, then cast the array to a procedure pointer and call it.

You may look at the CPU window to see how a function call is made in
assembly language.


Fernando Barbosa

unread,
May 25, 1999, 3:00:00 AM5/25/99
to

Peter Below (TeamB) <10011...@compuXXserve.com> escreveu na mensagem ...

>In article <7ieimm$t3...@forums.borland.com>, Fernando Barbosa wrote:
>> The situation is: I have a ClassName and a MethodName in my DB, can I
>> invoke this MethodName.
>>
>
>You can get the address of a *published* method (see MethodAddress),
>but you need an object (an instance of a class) to apply the method to,
>not simply a class. Having both you can construct a method pointer of
>an appropriate type, e.g.
>
> var
> m: TNotifyEvent;
> begin
> TMethod(m).data := someObject;
> TMethod(m).code := someObject.methodAddress( methodname );
> If assigned(m) then
> m( somesender );


I understand but I think this is not what I really need.

var
aClass: TClassComponent
aComponent: TComponent;
MethodPointer: Pointer;
begin
aClass := TClassComponent(FindClass ('SomeClassName'));
aComponent := aClass.Create(SomeOwner);
MethodPointer := aComponent.MethodAddress('SomeMethodName');

{ at this point I had to take all the method parameters (that are variables
and are in my DB - e.g. "Par1: string;
Par2: integer") and set them. Note that I know nothing about the method at
design time.}

end;

In the example that you sent me there is a method type. It's possible
to invoke a method without knowing its type or if it does't have a method
type ("procedure MethodName of object")


Robert Cerny

unread,
May 26, 1999, 3:00:00 AM5/26/99
to
Fernando Barbosa wrote in message <7if5km$8...@forums.borland.com>...

>
>
> In the example that you sent me there is a method type. It's possible
>to invoke a method without knowing its type or if it does't have a method
>type ("procedure MethodName of object")
>
>
>

Method type defines calling convention and parameters, so EVERY method (any
other functions also) has a type.
No, it's not possible to call generic method without knowing parameters. You
can however query for parameters of actual method (see TypInfo unit), but
you couldn't call it anyway, because you can't know for generic method what
does it expect in parameter values.

--
----------------------
Regards
Robert Cerny
Remove both qwe when replying
email: robert.q...@neosys.xrs.qwe.si

No questions via email, unless explicitly invited.


Peter Below (TeamB)

unread,
May 26, 1999, 3:00:00 AM5/26/99
to
In article <7if5km$8...@forums.borland.com>, Fernando Barbosa wrote:
> MethodPointer := aComponent.MethodAddress('SomeMethodName');
>
> { at this point I had to take all the method parameters (that are variables
> and are in my DB - e.g. "Par1: string;
> Par2: integer") and set them. Note that I know nothing about the method at
> design time.}
>

In this case you are forced to descend into the murky depth of BASM to
actually call the method. Unless you can reduce the number of actually used
method pointer types (parameter signatures) to a limited set you know at
compile time. Or can standardize on using a single method pointer type that
uses an open array of Variants or TVarRecs to accept variable number of
parameters.

If you have to go the BASM route then i suggest that you force all methods
that are to be called this way to use the stdcall or Pascal calling
convention. This makes it relatively easy to build the call stack since you
know that all parameters are passed on the stack. If you need to deal with
register calling convention you will go mad trying to figure out what goes
where if you can have a wild mix of parameter types in any combination and
sequence.

0 new messages