This is perfectly functional at least in Delphi7. Arctan2() is defined to handle the divide by zero case in itself. If you do it yourself it's double code (slower ofc).

[pascal]// Result = ]-180, 180]
const
ToRad = 0.0174532925199432; // PI / 180 = Deg to Rad
ToDeg = 57.295779513082320; // 180 / PI = Rad to Deg
function Angle(px1,py1,px2,py2: double): double;
begin
result:=ToDeg*arctan2(py2-py1,px2-px1);
// Add if result<0 then result:=result+360;
// if you want range to be [0..360[
end;[/pascal]

I also noticed that you negate X, which is false.