I recall having a function for that. I've looked it up:

[pascal]
function Direction2d(x1,y1,x2,y2: single): single;
begin
Result := radtodeg( arctan2((x2-x1) , (y2-y1)) )
end;
[/pascal]

The use of arctan2 is the key to the sollution of your problem. You must make sure that the second parameter is not zero. So you should add some if and then's to handle those cases.

The routine returns the angle in degrees. You only have to figure out, in which direction "zero degrees" points.

Hope to have helped you