我可以在Delphi中使用字符串"IsEmpty"方法吗?

Rod*_*ddy 5 delphi string

Embaracdero记录了字符串类型的"IsEmpty"方法,我已经成功地使用了C++ Builder代码.

WideString s;

if (s.IsEmpty())
   ....
Run Code Online (Sandbox Code Playgroud)

我从Delphi尝试了同样的东西,并且无法编译它:

var s: WideString;
begin
  if s.IsEmpty then
  ....
Run Code Online (Sandbox Code Playgroud)

我知道你可以用空字符串比较,或者调用Length函数,但是可以从Delphi调用这个IsEmpty方法吗?

编辑:只是为了澄清,这不是一个字符串与Widestring问题.

基本上,我链接到上面的文档描述了一个Pascal语法,以及一个C++语法,但这似乎不起作用.我认为这只是文档中的一个缺陷.

如果System :: WideString :: WideString为空,则返回true.

Pascal: function IsEmpty:bool;

idu*_*sun 14

String不是Delphi中的类,因此它没有方法,你必须使用函数进行字符串操作,如Length,Copy等... String是C++中的一个类,所以也许你对此感到困惑.


Cra*_*ntz 5

编号字符串不是WideString,即使在D2009中也是如此.你也不想要; 与nil/empty字符串比较比方法调用快得多.

在德尔福:

var 
  s: string;
begin
  if s = '' then begin
    ShowMessage('It is empty or nil.');
Run Code Online (Sandbox Code Playgroud)

... for string检测nil和空字符串(= nil).


Too*_*the 5

Delphi是一种混合语言.它包含基本类型和类.只有类(和记录和对象)可以包含方法.

String是一种基本类型,虽然是特殊类型.它是唯一具有保留字的类型.这就是为什么它通常使用小写(字符串)编写,而不像其他具有起始资本(Integer)的类型.

如果你愿意,你可以:

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;
Run Code Online (Sandbox Code Playgroud)