SRL Archive - Help and Support

Need to make this faster [text finding]


Narcle

2008-10-12 17:37:53

Its for my pickup in Nautilus, needs to have 'ake' in line.

function ChooseCount(Names: TStringArray): integer;
var
x, y, Ymod: integer;
B: TBox;
P: TPointArray;
i, H, ii, C: integer;
begin
GetClientDimensions(B.X2, B.Y2);
B.x1 := 0; B.y1 := 0;
FindColorsTolerance(P, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
If Length(P) = 0 Then
Exit;
B := GetTPABounds(P);
H := High(Names);
C := Round((B.Y2 - B.Y1 - 22) / 15);
Ymod := B.Y1 + 4;
for i := 0 to C do
begin
Ymod := Ymod + 15;
for ii := 0 to H do
if FindText(x, y, Names[ii], upchars, B.X1, Ymod-2, B.X2, Ymod+17) and
FindText(x, y, 'ake', upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
Result := Result + 1;
end;
end;

Lee Lok Hin

2008-10-16 10:31:44

function ChooseCount(Names: TStringArray): integer;
var
x, y, Ymod: integer;
B: TBox;
P: TPointArray;
i, H, ii, C: integer;
begin
GetClientDimensions(B.X2, B.Y2);
B.x1 := 0; B.y1 := 0;
FindColorsTolerance(P, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
If Length(P) = 0 Then
Exit;
B := GetTPABounds(P);
H := High(Names);
C := Round((B.Y2 - B.Y1 - 22) / 15);
Ymod := B.Y1 + 4;
for i := 0 to C do
begin
Ymod := Ymod + 15;
for ii := 0 to H do
if FindText(x, y, Names[ii], upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
if FindText(x, y, 'ake', upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
Result := Result + 1;
end;
end;

Should be slightly faster. It will only look for 'ake' if Names is there.

JuKKa

2008-10-16 10:47:08

Use FindTextTPA or what ever it is instead of Findtext

Naum

2008-10-16 12:11:08

Maybe use a 'Between' procedure to see if that name is inbetween the text, so you can check the names whilst checking the uptext

e.g

S := Between('string here','end string here', Rs_GetUpText);
If S = names Then

;)

Nava2

2008-10-16 14:23:46

Why not do GetTextAtEx then use a pos check like Nauman suggested?

Also, use Inc(Result) instead of Result := Result + 1;. Inc is faster, but IncEx is slower ;)

Narcle

2008-10-16 14:57:17

Guys I've already dealt with this issue awhile ago…

10-12-2008

4 Days late. :p

tarajunky

2008-10-16 16:24:30

So how'd you fix it then?

Wizzup?

2008-10-16 16:26:38

I hope he used FindTextTPA, like JuKKa nicely pointed out. :)

Narcle

2008-10-16 16:30:00

Did this:
function ChooseCount(Names: TStringArray): integer;
var
x, y, Ymod, T: integer;
B: TBox;
P: TPointArray;
i, H, ii, C: integer;
begin
T := GetSystemTime;
GetClientDimensions(B.X2, B.Y2);
B.x1 := 0; B.y1 := 0;
FindColorsTolerance(P, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
If Length(P) = 0 Then
Exit;
B := GetTPABounds(P);
H := High(Names);
C := Round((B.Y2 - B.Y1 - 22) / 15);
Ymod := B.Y1 + 4;
for i := 0 to C do
begin
Ymod := Ymod + 15;
if FindText(x, y, 'ake', upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
for ii := 0 to H do
if FindText(x, y, Names[ii], upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
begin
Inc(Result);
Break;
end;
end;
//writeln('ChooseCount took: '+inttostr(GetSystemTime - T)+'ms');
end;

40-70ms but it depends on computer and how big the choose option is. Before it was like 1-2secs >.>

Edit:
Btw I was going to use FindTextTPA but this worked fairly fast so I used it for now.

Nava2

2008-10-16 16:46:35

You might as well improve it. Assuming you don't follow the whole if aint broke don't fix it strategy.

Santa_Clause

2008-10-16 23:08:09

From: Narcle
Did this:
function ChooseCount(Names: TStringArray): integer;
var
x, y, Ymod, T: integer;
B: TBox;
P: TPointArray;
i, H, ii, C: integer;
begin
T := GetSystemTime;
GetClientDimensions(B.X2, B.Y2);
B.x1 := 0; B.y1 := 0;
FindColorsTolerance(P, 4674653, B.X1, B.Y1, B.X2, B.Y2, 0);
If Length(P) = 0 Then
Exit;
B := GetTPABounds(P);
H := High(Names);
C := Round((B.Y2 - B.Y1 - 22) / 15);
Ymod := B.Y1 + 4;
for i := 0 to C do
begin
Ymod := Ymod + 15;
if FindText(x, y, 'ake', upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
for ii := 0 to H do
if FindText(x, y, Names[ii], upchars, B.X1, Ymod-2, B.X2, Ymod+17) then
begin
Inc(Result);
Break;
end;
end;
//writeln('ChooseCount took: '+inttostr(GetSystemTime - T)+'ms');
end;

40-70ms but it depends on computer and how big the choose option is. Before it was like 1-2secs >.>

Edit:
Btw I was going to use FindTextTPA but this worked fairly fast so I used it for now.


But FindTextTPA is alot faster when it comes to many Text checks…I'm pretty sure that's what's used for random-finding nowadays.

Narcle

2008-10-16 23:50:53

Its an easy change, I'll get to it when I have time in any case. Moving Saturday so I have bunch of stuff to pack etc.