Reputation: 725
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
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
Reputation: 452
This should work too:
if AnsiUpperCase(vysledok) = AnsiUpperCase(meno) then
Upvotes: -1