相关疑难解决方法(0)

我应该何时在Delphi中使用增强记录类型而不是类?

Delphi 2006引入了新的记录功能,使其更加"面向对象".

在哪种情况下,记录类型更适合于设计而不是类类型?使用这些记录类型有哪些优势?

delphi oop class record delphi-2006

15
推荐指数
3
解决办法
5252
查看次数

在delphi中使用inline关键字是什么

任何人都可以说在delphi中使用内联关键字是什么

delphi

14
推荐指数
3
解决办法
1万
查看次数

Delphi中的运算符重载

是否有可能(在Delphi中)重载类中的运算符.我前段时间读过这篇文章只能用于记录,但是我发现的信息类似于以下代码中的类:

type
   TMyClass = class
     class operator Implicit(a: Integer): TMyClass;
   end;


class operator TMyClass.Implicit(a: Integer): TMyClass;
begin
   // ...
end;
Run Code Online (Sandbox Code Playgroud)

它是(修改)从地址:http: //docs.embarcadero.com/products/rad_studio/delphiAndcpp2009/HelpUpdate2/EN/html/devcommon/operatoroverloads_xml.html

但是当我尝试使用它时(在Delphi XE中)我得到:

预期的程序,功能,财产或VAR(E2123)

我想为矩阵操作创建我自己的简单类,并且在类中使用重载操作符的可能性是非常期待的机会.

Regars,Artik

delphi operator-overloading

6
推荐指数
1
解决办法
2771
查看次数

在将"增强记录"分配给普通"数据类型"变量时,我会使哪个运算符重载?

首先,我需要知道,如果我想做的事情是可能的.如果有可能,我需要知道如何.

它更容易证明问题​​而不是解释它,所以这里:

我有一个"增强记录"(目的 - 虽然对这个问题不重要 - 是产生一个"智能字符串"类型,以取代普通的字符串类型):

TLKString = record
  Value: String;
  // Some methods here to operate on and build String values

  // Allows me to assign String values directly to "instances" 
  // of this record type! I have others (hence "overload") to 
  // handle other data types (such as Integer etc.)
  class operator Implicit(const AValue: String): TLKString; overload; 
end;
Run Code Online (Sandbox Code Playgroud)

我现在可以使用这个TLKString类型,如下所示:

var
  LSmartString: TLKString;
begin
  LSmartString := 'Hello World'; // The "Implicit" operator then 
                                 // assigns this to LSmartString.Value …
Run Code Online (Sandbox Code Playgroud)

delphi overloading record operator-keyword delphi-xe2

4
推荐指数
1
解决办法
268
查看次数