Delphi Error – E2198 %s cannot be applied to a long string

Delphi Compiler Error

E2198 %s cannot be applied to a long string

Reason for the Error & Solution

It is not possible to use the standard function HIGH with long strings. The standard function HIGH can, however, be applied to old-style short strings.

Since long strings dynamically size themselves, no analog to the HIGH function can be used.

This error can be caused if you are porting a 16-bit application, in which case the only string type available was a short string. If this is the case, you can turn off the long strings with the $H command line switch or the long-form directive $LONGSTRINGS.

If the HIGH was applied to a string parameter, but you still wish to use long strings, you could change the parameter type to ‘openstring’.

program Produce;
  var
    i : Integer;
    s : String;

begin
  s := 'Hello Developers of the World';
  i := HIGH(s);
end.

In the example above, the programmer attempted to apply the standard function HIGH to a long string variable. This cannot be done.

(*$LONGSTRINGS OFF*)
program Solve;
  var
    i : Integer;
    s : String;

begin
  s := 'Hello Developers of the World';
  i := HIGH(s);
end.

By disabling long string parameters, the application of HIGH to a string variable is now allowed.

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Delphi Compiler Error X2421 Imported identifier ‘%s’ conflicts with ‘%s’ in ‘%s’ Reason for the Error & Solution This occurs...
Delphi Compiler Error X2367 Case of property accessor method %s.%s should be %s.%s Reason for the Error & Solution No...
Delphi Compiler Error X2269 Overriding virtual method ‘%s.%s’ has lower visibility (%s) than base class ‘%s’ (%s) Reason for the...