The MASM Forum

Projects => ObjAsm => Topic started by: HSE on June 11, 2015, 03:33:39 AM

Title: How to use a method of a diferent object?
Post by: HSE on June 11, 2015, 03:33:39 AM
Hi!

In translating a Java application to Masm32 a new question have come to light.

There is a sounded technic to allow an object could use another object's method?

In Java is easy, but is a JVM runtime trick (if I remember well).



public class father {
Child1 hijo1;
Child2 hijo2;

void make(){
hijo1.padre = this; 
hijo2.padre = this; 
hijo1.makeSomething1();
}
}

public class Child1 {
father padre;
void makeSomething1(){
padre.hijo2.makeSomething2();
}
void makeSomething3(){
int v3 = 1;
}
}

public class Child2 {
father padre;
void makeSomething2(){
int v1 = 0;
}
void makeSomething4(){
padre.hijo1.makeSomething3();
}
}



There is no problem in following the chain of pointers. But compilation is sequential, and the compiler don't understand not yet compiled object's methods.

Thanks. HSE
Title: Re: How to use a method of a diferent object?
Post by: Biterider on June 11, 2015, 06:34:36 AM
Hi HSE
I'm not sure I get you correctly, but if you have a pointer to an object, you can allways cast the call (OCall) so that the pointer is interpreted in the way you want.
This is to say, that you can OCall esi::YourObject.YourMethod where esi is the pointer and the cast is YourObject.
Note: YourObject may be also an ancestor if you don't know exactly of you are calling a specialized object from a container object.

Biterider
Title: Re: How to use a method of a diferent object?
Post by: HSE on June 11, 2015, 09:16:26 AM
Apparently, OCall esi::YourObject.YourMethod work well when YourObject was previouly compiled (even if YourObject is not related at all with the calling object)

The problem is that, in interlaced objects, the compiler don't recognize YourObject.YourMethod, because it not read YourObject yet. If you change the order, YourObject became the problem because the compiler not read the other object yet.   

I don't know if some kind of PROTO or externdef declaration can make the trick. More knowledge than mine is needed.

If there isn't a known solution, I will try, perhaps its posible the connection trough an ancestor.

Thanks. HSE






Title: Re: How to use a method of a diferent object?
Post by: Biterider on June 12, 2015, 01:25:11 AM
Hi
OK, now I understand your problem. The solution is easy.
You have to write the declaration of all objects first followed by the IMPLEMENTATION. This way, the compiler knows all about the called objects in the implementation section.
As an example, look into the D3Engine.inc file of the Api3DEng project.

Biterider
Title: Re: How to use a method of a diferent object?
Post by: HSE on June 13, 2015, 07:42:48 AM
Hi Biterider

Perfect

Thanks. HSE