SRL Archive - Research & Development Lounge

Two UpText Functions


drizzt

2008-03-21 10:02:11

here are two Uptext Functions i made,


{Returns the uptext that is there out of the "possible" string array in the
variable Item and returns true/false whether or not one is found}

Function WhatIsUpText(var Item: String; Possible: TStringArray): Boolean;
var
h, highest, l: integer;
t: String;

begin
t := rs_getupText;
highest := High(Possible);
for h := 0 to highest do
begin
if pos(Possible[h],t) <> 0 then
begin
inc(l);
Item := Possible[h];
end;
end;
if l = 1 then
Result := True
else
begin
Result := False;
Item := '';
end;
end;


{Returns whether or not all the strings are found in the Uptext}

Function AllUpTexts(Texts: TStringArray): Boolean;
var
h, i, Many: integer;
t: String;
begin
t := rs_GetUpText;
h := high(Texts);
for i := 0 to h do
begin
if pos(Texts[h], t) <> 0 then inc(many);
end;
if Many = length(Texts) then Result := true;
end;

if they don't work for you, tell me.

n3ss3s

2008-03-21 10:22:24

Those had a lot of errors, please test before posting.


Function WhatIsUpText(var Item: String; Possible: TStringArray): Boolean;
var
h, highest, l: integer;
t: String;

begin
t := rs_getupText;
highest := High(Possible);
for h := 0 to highest do
if pos(Possible[h],t) <> 0 then
begin
inc(l);
Item := Possible[h];
end;
if l = 1 then
Result := True
else
begin
Result := False;
Item := '';
end;
end;



Function AllUpTexts(Texts: TStringArray): Boolean;
var
h, i, Many: integer;
t: String;
begin
t := rs_GetUpText;
h := high(Texts);
for i := 0 to h do
if pos(Texts[i], t) > 0 then inc(many);
if Many = length(Texts) then Result := true;
end;

drizzt

2008-03-21 10:28:13

from what i see you've changed, its not really an error, just took out an unnecessary begin/end; on each.

and it is the public test corner, so i figured the public could test it.

n3ss3s

2008-03-21 10:39:29

Haha, you are wrong - try to run your ones.


a) In both functions you tried to store the uptext to an integer.
b) In the other you forgot a close round.
c) You can't have a semicolon after the first statement in an If - Then - Else.
d)
 var Item: String, 
e)
 if pos(Texts, t) then 
You forgot the comparing
f)
 pos(Texts, t) 
You tried to find the postion of a TStringArray?


Have a nice day.

drizzt

2008-03-21 10:45:50

wow. i can't believe i messed up that much in a simple little function. thank you for pointing those out

all fixed and tested, work beautifully.