问题
Scar Divi Float or Double to Int. How I pass a Float/Double to Integer?
Here's the code. I'm trying to Find the bitmap and click on the center, the problem is when I try to divide the x or y to find the img center.
program FindBitmap;
label
main;
var
Bmp: TSCARBitmap;
x, y: Integer;
temp1, temp2: String;
begin
ClearDebug;
Bmp := TSCARBitmap.Create('deNqtzGkKglAUhuE2Ea2pwXm8atpAFCIVRdEKi' +
'qJCkBBpAeVQa+zCBRGH++cEz6/Dd95Oq92ajoZwE8eCG9sm3GhowDkWgrNNHc4' +
'yNDgTqbnz6fjNMrr49XIXs+IXZuhK0fVyphSS99tz56UXDGlyEb7491ttIY3jp' +
'eeW9oSuSCVIlQPfLxWyJFkvveqY0GSxCnceQZAXPmm6Xa9ql4QqCbVwJwpDEtl' +
'vN00zQhb5JkhTnlF02O8oG0ISOApFEugDQuRZOIFj4Hh2AMcxfTh20PuDfhfuB' +
'32bFT0=');
main:
if FindBitmap (x, y, Bmp, 0, 0, 2559, 1023) then
begin
WriteLn('IMG FOUND!');
ClickMouse((x + Bmp.Width / 2),(y + Bmp.Height / 2),mbLeft);
end
else
begin
goto main
end;
end.
ClickMouse doesn't work, Scar Divi says: Type mismatch
回答1:
To convert a datatype, you "cast" it (not "pass"). See this link.
ClickMouse(Integer(x + Bmp.Width / 2),Integer(y + Bmp.Height / 2),mbLeft);
When I look at the definition of ClickMouse, it wants not just an Integer
, it wants a const Integer
for all its parameters:
procedure ClickMouse(const X, Y: Integer; const Btn: TMouseButton);
By definition, a const
has to be evaluatable at compilation time. If I understand that correctly, then the approach you are taking cannot work...
回答2:
Ok, tanks to all. Sertac Akyuz had the solution: change the / for a div to return an integer.
ClickMouse((x + Bmp.Width div 2),(y + Bmp.Height div 2),mbLeft);
The problem was that I can't have a decimal coordinate.
来源:https://stackoverflow.com/questions/14551562/scar-divi-float-or-double-to-int