我有两个相同代码的变体:
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
IMyObject1 = interface
['{4411181F-3531-4D30-AB18-A8326F8C2CD0}']
end;
IMyObject2 = interface
['{41C88E1A-0360-4AC3-B021-125880B23DE5}']
end;
TMyObject = class(TInterfacedObject, IMyObject1, IMyObject2)
public
destructor Destroy; override;
end;
destructor TMyObject.Destroy;
begin
Writeln('Destroy');
inherited;
end;
procedure Variant1;
function GetMyObject: IMyObject2;
var
Obj1: IMyObject1;
begin
Obj1 := TMyObject.Create;
try
Obj1.QueryInterface(IMyObject2, Result);
finally
Obj1 := nil;
end;
end;
var
Obj2: IMyObject2;
begin
Obj2 := GetMyObject;
try
finally
Obj2 := nil;
end;
Writeln('Variant1 end of proc');
end;
function GetMyObject: IMyObject2;
var
Obj1: IMyObject1;
begin
Obj1 := …Run Code Online (Sandbox Code Playgroud) 我一直认为OleVariant变量的初始值总是等于Unassigned(类型VT_EMPTY).但是下面用XE3编译的简单代码告诉我这不是真的.
{$APPTYPE CONSOLE}
uses
ActiveX;
function GetValue: OleVariant;
begin
Result := TVariantArg(Result).vt;
end;
function GetValue2: OleVariant;
begin
Result := 10;
Result := GetValue;
end;
var
Msg: string;
begin
Msg := GetValue2;
Writeln(Msg);
end.
Run Code Online (Sandbox Code Playgroud)
App写"3".这是正常的吗?
delphi ×2