在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 7中初始化Widestring,但我不能使用chrANSI的函数
var
ws : Widestring;
begin
ws := chr($FFFF) + chr($FFFF) + chr($FFFF);
end;
Run Code Online (Sandbox Code Playgroud)
那我可以用什么?
谢谢
在阅读了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)