相关疑难解决方法(0)

"参考"解决了什么问题

在Chris的博客上:http://delphihaven.wordpress.com/2011/07/14/weird-in-more-ways-than-one/

我找到了以下代码

type
  TLinkVisitor<T> = reference to procedure(const Item: T);

  TDoubleLinked<T> = record
    Prev: ^TDoubleLinked<T>;
    Next: ^TDoubleLinked<T>;
    Value: T;
    class function Create(const aValue: T): Pointer; static;
    function Add(const aValue: T): Pointer;
    procedure Delete;
    procedure DeleteAll;
    function First: Pointer;
    function Last: Pointer;
    procedure ForEach(const Proc: TLinkVisitor<T>);
  end;
Run Code Online (Sandbox Code Playgroud)

"引用"关键字解决了哪些问题无法通过正常的程序类型完成?

delphi generics anonymous-methods

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

在Delphi 7中,chr等效于Unicode

我需要在Delphi 7中初始化Widestring,但我不能使用chrANSI的函数

var
  ws : Widestring;
begin

 ws := chr($FFFF) + chr($FFFF) + chr($FFFF);

end;
Run Code Online (Sandbox Code Playgroud)

那我可以用什么?

谢谢

delphi delphi-7

2
推荐指数
1
解决办法
1525
查看次数

是否可以初始化函数的常量引用数组?

在阅读了Embarcadero关于程序类型匿名方法的文档以及David Heffernan对此问题的解释后,我仍然不太明白为什么编译器禁止初始化函数的常量引用数组,如下例中的C_BAR.

program MyProgram;

{$APPTYPE CONSOLE}

{$R *.res}

type
  TFoo = function: Integer;
  TBar = reference to function: Integer;

  function FooBar: Integer;
  begin
    Result := 42;
  end;

const
  // This works
  C_FOO: array[0..0] of TFoo = (FooBar);

  // These lines do not compile
  // C_BAR: array[0..0] of TBar = (FooBar); // TBar incompatible with Integer
  // C_BAR: array[0..0] of TBar = (@FooBar); // TBar incompatible with Pointer

var
  Foo: array[0..0] of TFoo; …
Run Code Online (Sandbox Code Playgroud)

delphi delphi-10.1-berlin

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