Quote Originally Posted by AthenaOfDelphi
In terms of object orientated programming, the most widely used way is to do what Paul has suggested. Declare the method in the base class as 'virtual' and then override it in the child classes.

By doing it that way, if your base class has functionality in it that will also be needed for the children, you can use the 'inherited' keyword to call the common functionality.

To use the procedure variable method (which is the standard eventing mechanism), you should really handle the situation where the variable is not initialised, which would result in an additional 'if assigned()' or 'if collide<>nil' style check to avoid attempting to call a routine at address 0x00000000 (which I'm guessing is why your code isn't working using that method). If the routine is being called alot, then those checks create an overhead that can be avoided by using real overrides.
Well I have 2 main problems with this.
1. (I believe) I'd have to create a separate class each time I want different collision code
2. The way I'm writing this is engine is so the engine manages all of the objects

Quote Originally Posted by de_jean_7777
You could assign some procedure to the procedure variable in your unit in the
Code:
INITIALIZATION
part. This way you can assign your procedure variable a default procedure, and you won't have to check if it is nil. This is what I do in my projects, though you do have to be careful that your procedure variables are always initialized if you do not want to do checking.

I usually assign procedure variables some dummy procedures in the INITIALIZATION part. These dummy routines do nothing, but they prevent crashes in case of a call to a nil procedure variable. Then later on I assign them some other procedure.
I never think of the simple things...

Ok, so now for the sake of organization and (somewhat) cleaner code, how can I pass variables into the collide procedure? (Because assigning procedures without using the way Paul showed means the procedure does not have access to the object's variables).

So I was thinking:
Code:
 Sprite = Object 
     public 
        x,y,xspeed,yspeed,gravity,lastx,lasty,collision: integer; 
        solid: boolean; 
        img: TBitmap; 
        procedure Create(); 
        procedure Destroy(); 
        Collide: procedure(index: integer) of object; // Empty by default. I want to override it. 
  end;

...

Player: Sprite; 
Player := Sprite.Create; 
Player.Collide := @PlayerCollide; // Yells at me here

...

procedure PlayerCollide(index: Integer);
begin

end;
But it yells at the same line as before when I try that.

(PS: Might want to post somewhere how to use code highlighting on these forums)