Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I use string "IsEmpty" methods in Delphi

Tags:

string

delphi

Embaracdero documents "IsEmpty" methods for string types, which I've used successfully with C++ Builder code.

WideString s;

if (s.IsEmpty())
   ....

I tried the same from Delphi, and couldn't get it to compile:

var s: WideString;
begin
  if s.IsEmpty then
  ....

I know you can compare with an empty string, or call the Length function, but is it possible to call this IsEmpty method from Delphi?

EDIT: Just to clarify, this wasn't meant as a String vs Widestring issue.

Basically, the docs I link to above describe a Pascal syntax, as well as a C++ one, yet this doesn't seem to work. I assume this is just a flaw in the documentation.

Returns true if the System::WideString::WideString is empty.

Pascal: function IsEmpty: bool;

like image 891
Roddy Avatar asked Jun 19 '09 12:06

Roddy


2 Answers

String is not a class in Delphi therefore it has no methods, you have to use functions for string manipulations like Length, Copy, etc... String is a class in C++ so maybe you are confused by that.

like image 81
idursun Avatar answered Oct 03 '22 11:10

idursun


Delphi is an hybrid language. It contains basic types and classes. Only classes (and records and objects) can contain methods.

String is a basic type, although a special one. It's the only type that has a reserved word. That's why its often written with a lowercase (string) unlike other types which have a starting captial (Integer).

You can if you like:

type
  TString = class
  private
    FString: string;
  public
    constructor Create(const AValue: string);

    property &String: string read FString write FString;
    property IsEmpty: Boolean read GetIsEmpty;
    // ...
  end;
like image 25
Toon Krijthe Avatar answered Oct 03 '22 11:10

Toon Krijthe