My knowledge on this is a 'tad rusty, but I think I can help you.
procedure Example();
var
x, y: Integer;
b: TBox;
begin
b := (IntToBox(x + 25, y + 25, x - 25, y - 25));
if ... then
begin
end;
end;
Let me explain what we're doing here. We first define x and y as integers and we also define b as a TBox (that's just 4 values to make a box).
Once we define those variables, we make b's values (x1, y1, x2, y2) to be dependant on x and y's values. So we take x and increase it by 25, y by 25 and then decrease the next x and y values.
This makes a box of 25 pixels above and lower than the x and y values. This will allow us to search within the box. That's where the if … then comes in and you replace it with what you want.
E: Just for a little 'bit more insight: If you know TPAs & 2D TPAs well enough, you can get the boundaries of a 2D TPA and make a box around it with the size you desire. This will allow you to accurately enough tell where the HP bar is and judge what you want to do based on that.
I'm very rusty at this so I can't explain it very well, but I hoped that help a little.