Wed, 18 Jun 1902 08:00:00 GMT
Getting a method's address
QuoteIn article <4p03r7$...@hume.nmia.com> Mark Iuzzolino wrote: >I'm having a problem getting the address of procedure that is within an >object. Here is an example of what I'd like to do: >type foo:object > Proc:procedure; > procedure ActualProc1; > procedure ActualProc2; > end; >procedure foo.ActualProc1; >begin > Proc:=ActualProc2; >end; >procedure foo.ActualProc2; >begin > Proc:=ActualProc1; >end; >BP says that it is an Invalid procedure or function reference. Everything is >compiled far, so that is not the problem. Does anyone know of a way to get >around this, or to get the address of a method in an object?
A procedure and a method are not the same. I don't know how to explain it except in how the underlying code is put together. Since your procedure takes no parameter, it compiles to a simple call instruction. The methods however have a hidden parameter pushed to the stack. This is Self, which is a pointer to the object's instance. Definitely not the same as a procedure. The only way that I know to handle this situation is to make the two methods far procedures that receive a pointer to the object, or receive the object as a var parameter. Shortcoming is that they can only access public variable and methods. If you know which method is needed before the object is initialized, you could make the method virtual and declare two separate types. Then simply construct the proper type. Any other ideas? -- RDon...@gnn.com http://members.gnn.com/rdonais/index.html ------------------------------------------- Knowledge is one of the few things that you can give away and still keep for yourself.
|