Recent

Author Topic: Operator is not overloaded: not "AnsiString"?  (Read 1432 times)

ShungFeng

  • New Member
  • *
  • Posts: 20
Operator is not overloaded: not "AnsiString"?
« on: February 21, 2020, 11:49:08 am »
Hi!  :)

I'm trying to compare two strings, but I get the error:

Quote
Operator is not overloaded: not "AnsiString"

Code: Pascal  [Select][+][-]
  1. var
  2.   a, b, c: string;
  3. begin
  4.   b := c + 'text'
  5.  
  6.   if not a = b then
  7.     DoSomething();
  8. end;

How can I fix this error?

bytebites

  • Hero Member
  • *****
  • Posts: 639
Re: Operator is not overloaded: not "AnsiString"?
« Reply #1 on: February 21, 2020, 11:55:00 am »
Code: Pascal  [Select][+][-]
  1. if not (a = b) then
  2.     DoSomething();

or

Code: Pascal  [Select][+][-]
  1. if  a <> b then
  2.     DoSomething();

ShungFeng

  • New Member
  • *
  • Posts: 20
Re: Operator is not overloaded: not "AnsiString"?
« Reply #2 on: February 21, 2020, 12:06:57 pm »
Thank you! The first one worked.

uart

  • Jr. Member
  • **
  • Posts: 58
Re: Operator is not overloaded: not "AnsiString"?
« Reply #3 on: February 21, 2020, 12:13:06 pm »
but I get the error: "Operator is not overloaded: not "AnsiString"

The reason your code fails is that "not" is a higher precedence logical operator than "=".

So Pascal thinks that you are trying to do: if not (a) = b then ..., and is complaining that it doesn't know how to do the "not" of a string.

See: https://www.freepascal.org/docs-html/ref/refch12.html

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1314
    • Lebeau Software
Re: Operator is not overloaded: not "AnsiString"?
« Reply #4 on: February 21, 2020, 09:18:38 pm »
So Pascal thinks that you are trying to do: if not (a) = b then ...

I think you mean: if (not a) = b then ...
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

 

TinyPortal © 2005-2018