PDA

View Full Version : Two UpText Functions



drizzt
03-21-2008, 02:02 PM
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
03-21-2008, 02:22 PM
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
03-21-2008, 02:28 PM
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
03-21-2008, 02:39 PM
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
03-21-2008, 02:45 PM
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.