user2886091
user2886091

Reputation: 725

string1.Equals(string2) in if statement - no such member as Equals and expression must be BOOLEAN

I am trying to make a if statement where I want to compare 2 strings, whether they are equal or not in condition.

This is what I have

 if  vysledok.Equals(meno) then
 Application.MessageBox('Zadane meno existuje, zadajte prosím iné meno','DUPLICITNÝ UŽÍVATEĽ',0)
 else
 ...

However vysledok.Equals(meno) is underlined and it says this:

 'string' does not contain a member named 'Equals' at line ...
  Type of expression must be BOOLEAN at line ...

I have to mention that I am new to delphi :) Thank you for advice

Upvotes: 3

Views: 348

Answers (2)

David Heffernan
David Heffernan

Reputation: 612954

In modern Delphi, the helper for the string type, defined in SysUtils, provides an Equals method. So, in XE3 or later, if you use SysUtils, your code will compile. From which we can surmise that you are using an older version of Delphi, or have not used SysUtils.

In older versions of Delphi you compare strings using the equality operator:

if vysledok = meno then

In fact, the implementation of the Delphi string helper Equals method does nothing more than compare using this equality operator.

Should you want a case insensitive comparison use SameText():

if SameText(vysledok, meno) then

Upvotes: 4

Izuel
Izuel

Reputation: 452

This should work too:

if AnsiUpperCase(vysledok) = AnsiUpperCase(meno) then

Upvotes: -1

Related Questions