Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: if stra[1] <> strb[1] - "Operator not applicable to this operand type"


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 4 - Last Post: Apr 2, 2018 3:12 PM Last Post By: Remy Lebeau (Te...
Ken Knopfli

Posts: 4
Registered: 4/5/18
if stra[1] <> strb[1] - "Operator not applicable to this operand type"  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 1:44 AM
This is condensed from GraphicEx from the Virtual Tree View people.

If I compile the following (in Tokyo)

var
ZLIB_VERSION: String[10] = '1.1.2';
s: string;

procedure TForm1.FormClick(Sender: TObject);
begin
s := 'hello world';
if s[1] <> ZLIB_VERSION[1] then // <-- dcc32 Error E2015
...

I get the compiler error

"Operator not applicable to this operand type"

Edited by: Ken Knopfli on Apr 2, 2018 1:46 AM
Peter Below

Posts: 1,227
Registered: 12/16/99
Re: if stra[1] <> strb[1] - "Operator not applicable to this operand type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 3:24 AM   in response to: Ken Knopfli in response to: Ken Knopfli
Ken Knopfli wrote:

This is condensed from GraphicEx from the Virtual Tree View people.

If I compile the following (in Tokyo)

var
ZLIB_VERSION: String[10] = '1.1.2';
s: string;

procedure TForm1.FormClick(Sender: TObject);
begin
s := 'hello world';
if s[1] <> ZLIB_VERSION[1] then // <-- dcc32 Error E2015
...

I get the compiler error

"Operator not applicable to this operand type"

It compiles with typecast:

if s[1] <> Char(ZLIB_VERSION[1]) then

The legacy string[N] type contains ANSI characters while the standard
string type contains Unicode (UTF16) characters. Looks like there is no
automatic type conversion between ANSI and Unicode anymore in
statements like your original.


--
Peter Below
TeamB

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: if stra[1] <> strb[1] - "Operator not applicable to this operand type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 10:14 AM   in response to: Peter Below in response to: Peter Below
Peter Below wrote:

Looks like there is no automatic type conversion between ANSI and
Unicode anymore in statements like your original.

There never was, for individual characters. Only for whole strings.

--
Remy Lebeau (TeamB)
Ken Knopfli

Posts: 4
Registered: 4/5/18
Re: if stra[1] <> strb[1] - "Operator not applicable to this operand type" [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 2:25 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
The above is from the MZLib.pas unit from Mike Lischke's GraphicEx library,

function DeflateInt2,

Would that mean GraphicEx never compiled?
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: if stra[1] <> strb[1] - "Operator not applicable to this operand type" [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 3:12 PM   in response to: Ken Knopfli in response to: Ken Knopfli
Ken Knopfli wrote:

The above is from the MZLib.pas unit from Mike Lischke's GraphicEx
library,

function DeflateInt2,

Would that mean GraphicEx never compiled?

More likely, you are trying to compile a version of GraphicEx that is
intended for pre-Unicode versions of Delphi. Make sure you are
compiling the right version.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02