Theoretically the only factor you should need to adjust for in the following equation when zooming is the focal length:
distance to object (mm) = focal length (mm) * real height of the object (mm) * image height (pixels)
---------------------------------------------------------------------------
object height (pixels) * sensor height (mm)
There is one factor to be aware of, the distance to object in this equation is actually the distance from the object to the centre of projection of the lens (usually somewhere in the middle of the lens on the optical axis).
However, the centre of projection will usually move when you zoom or focus a lens. The original question was about finding the distance to a windmill, so if the centre of projection moved a few cm it would have a negligible effect on the answer. But if you are attempting to measure very close objects it could skew the result.
What is more likely though is the EXIF reported focal length is only approximate, most lenses only supply about 8 different values for focal length. Not only that but the focal length written on the lens is also inaccurate (it's usually rounded to the nearest 5mm for marketing purposes), and the lens focal length will likely change when focussing also.
In short a camera is a poor tool for measuring distances, especially at close range where a far more accurate solution is possible using a tape measure.