Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

whats the best way to do this ?? 3

Status
Not open for further replies.

DelphiAaron

Programmer
Jul 4, 2002
826
AU
this isnt my code but this is what i want to do.

if string = 'word1' or 'word2' or 'word3' or 'word4'
then checkbox.checked:=True
else checkbox.checked:= False;

Aaron Taylor
John Mutch Electronics
 
Code:
Checkbox1.Checked := (sString='word1') or (sString='word2')
    or (sString='word3') or (sString='word4');
Specify the constants in the order they will most likely occur, and be sure the compiler option for "Complete boolean eval" is unchecked. That way as soon as one of the compares tests true further testing is not performed.
 
This code in CaseInSensitive

Code:
function AmongStr(const InStr: string; const Strings: array of string): Boolean;
var
  i: Integer;
begin
  Result := false;
  for i := 0 to High(Strings) do
    if Comparetext(Strings[i], InStr) = 0 then
    begin
      Result := true;
      Exit;
   end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  CheckBox1.Checked := AmongStr('Test', ['as','test']);
end;

KungTure-RX.jpg

//Nordlund
 
I copied this out of another group and kept it in my "bag of tricks" ... so it's not tested...

--------------------------------------------------
That's easy. Borland, finally, added some functions for this
purpose: StrUtils.pas

if AnsiMatchText (Edit1.Text, ['this','that'] then // case insensitive
begin
...
end;

or use AnsiMatchStr for case sensitive string-comparing.
---------------------------------------------------




Regards and HTH,
JGS
 
thanx guys, its good to have some different ideas.
i'll keep them in my code snippet library.
stars for all.

Aaron Taylor
John Mutch Electronics
 
Tnx Aaron .... guess we "all" have snippet buckets ...

JGS
 
Hehe... My little snippet was done in Delphi 5
and AnsiMatchText is similar to my code.

Well, I can now replace my little "old-snippet".


-"Delphi, bless you all"

KungTure-RX.jpg

//Nordlund
 
I know.
Therefore the alternate solution.

God bless u all...

KungTure-RX.jpg

//Nordlund
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top