在Delphi中取消引用和分配指针的语法

时间:2018-07-09 10:32:13

标签: delphi pointers

需要实现一种接口方法,在该方法中传递了一个指针,并且期望该方法取消引用该指针并为其分配OleVariant。这样做的语法是什么?

// Code I have no access to change
function GetEntry: string;
var
  value: OleVariant;
begin
  Entry(@value);  
  Result := VarToStr(value);
end;

// My code  
procedure Entry(Value: Pointer);
begin
  Value^ := ??? // Not sure whats the syntax here in order to assign an OleVariant
end

1 个答案:

答案 0 :(得分:8)

您可以使用这样的值转换:

OleVariant(Value^) := ...

或者,您可以投射指针:

POleVariant(Value)^ := ...