procedure RoadWalkTol2(RColor: Integer; Dir: String; Tol: Integer);
var
c : Integer;
begin
Uppercase(Dir);
if (Dir = 'S') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 565, 160 - c, 725, 160, Tol)) then
begin
MouseFindFlag(x, y, 0, -1);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'SE') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 725 - c, 160 - c, 725, 160, Tol)) then
begin
MouseFindFlag(x, y + 5, -1, -1);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'SW') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 565, 160 - c, 565 + c, 160, Tol)) then
begin
MouseFindFlag(x + 5, y + 5, 1, -1);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'N') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 565, 5, 725, 5 + c, Tol)) then
begin
MouseFindFlag(x, y, 0, 1);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'NE') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 725 - c, 5, 725, 5 + c, Tol)) then
begin
MouseFindFlag(x, y + 5, -1, 1);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'NW') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 565, 5, 565 + c, 5 + c, Tol)) then
begin
MouseFindFlag(x, y + 5, 1, 1);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'E') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 725 - c, 5, 725, 160, Tol)) then
begin
MouseFindFlag(x, y + 5, -1, 0);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
if (Dir = 'W') then
begin
repeat
c := c + 5;
if (FindColorTolerance(x, y, RColor, 565, 5, 565 + c, 160, Tol)) then
begin
MouseFindFlag(x, y + 5, 1, 0);
CountFlag(10);
Break;
end;
until (c >= 100);
end;
end;
That should work, countflag will auto update the roadcolor.