mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-06-07 15:19:07 +02:00
* VarUtils, fixed missing support for interfaces
- NoInterfaces() not used anymore, removed + Basic test for VariantArray of IInterface git-svn-id: trunk@16527 -
This commit is contained in:
parent
4e3cedb492
commit
5bf51c991c
1
.gitattributes
vendored
1
.gitattributes
vendored
@ -9910,6 +9910,7 @@ tests/test/units/sysutils/trwsync.pp svneol=native#text/plain
|
|||||||
tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain
|
tests/test/units/sysutils/tsscanf.pp svneol=native#text/plain
|
||||||
tests/test/units/sysutils/tstrtobool.pp svneol=native#text/plain
|
tests/test/units/sysutils/tstrtobool.pp svneol=native#text/plain
|
||||||
tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
|
tests/test/units/variants/tcustomvariant.pp svneol=native#text/plain
|
||||||
|
tests/test/units/variants/tvararrayofintf.pp svneol=native#text/plain
|
||||||
tests/test/uobjc24.pp svneol=native#text/plain
|
tests/test/uobjc24.pp svneol=native#text/plain
|
||||||
tests/test/uobjc26.pp svneol=native#text/plain
|
tests/test/uobjc26.pp svneol=native#text/plain
|
||||||
tests/test/uobjc27a.pp svneol=native#text/plain
|
tests/test/uobjc27a.pp svneol=native#text/plain
|
||||||
|
@ -13,16 +13,6 @@
|
|||||||
|
|
||||||
**********************************************************************}
|
**********************************************************************}
|
||||||
|
|
||||||
Resourcestring
|
|
||||||
|
|
||||||
SNoInterfaces = 'No interfaces supported';
|
|
||||||
|
|
||||||
Procedure NoInterfaces;
|
|
||||||
|
|
||||||
begin
|
|
||||||
Raise Exception.Create(SNoInterfaces);
|
|
||||||
end;
|
|
||||||
|
|
||||||
Procedure VariantTypeMismatch; overload;
|
Procedure VariantTypeMismatch; overload;
|
||||||
begin
|
begin
|
||||||
Raise EVariantError.CreateCode(VAR_TYPEMISMATCH);
|
Raise EVariantError.CreateCode(VAR_TYPEMISMATCH);
|
||||||
|
@ -156,7 +156,7 @@ begin
|
|||||||
varVariant : Variant(VargDest):=Variant(PVarData(VPointer)^);
|
varVariant : Variant(VargDest):=Variant(PVarData(VPointer)^);
|
||||||
varOleStr : CopyAsWideString(VargDest.VOleStr,PVarData(VPointer)^.VoleStr);
|
varOleStr : CopyAsWideString(VargDest.VOleStr,PVarData(VPointer)^.VoleStr);
|
||||||
varDispatch,
|
varDispatch,
|
||||||
varUnknown : NoInterfaces;
|
varUnknown : IInterface(VargDest.vUnknown):=IInterface(PInterface(VargSrc.VPointer)^);
|
||||||
else
|
else
|
||||||
Exit(VAR_BADVARTYPE);
|
Exit(VAR_BADVARTYPE);
|
||||||
end;
|
end;
|
||||||
@ -737,9 +737,11 @@ begin
|
|||||||
vatNormal:
|
vatNormal:
|
||||||
Move(P^, Data^, psa^.ElementSize);
|
Move(P^, Data^, psa^.ElementSize);
|
||||||
vatInterface:
|
vatInterface:
|
||||||
NoInterfaces; // Just assign...
|
IInterface(PInterface(Data)^) := IInterface(PInterface(P)^);
|
||||||
vatWideString:
|
vatWideString:
|
||||||
CopyAsWideString(PWideChar(Data^), PWideChar(P^));
|
CopyAsWideString(PWideChar(Data^), PWideChar(P^));
|
||||||
|
vatVariant:
|
||||||
|
VariantCopy(PVarData(Data)^, PVarData(P)^);
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
On E : Exception do
|
On E : Exception do
|
||||||
@ -762,9 +764,11 @@ begin
|
|||||||
vatNormal:
|
vatNormal:
|
||||||
Move(Data^,P^,psa^.ElementSize);
|
Move(Data^,P^,psa^.ElementSize);
|
||||||
vatInterface:
|
vatInterface:
|
||||||
NoInterfaces;
|
IInterface(PInterface(P)^):=IInterface(Data);
|
||||||
vatWideString:
|
vatWideString:
|
||||||
CopyAsWideString(PWideChar(P^), PWideChar(Data));
|
CopyAsWideString(PWideChar(P^), PWideChar(Data));
|
||||||
|
vatVariant:
|
||||||
|
VariantCopy(PVarData(P)^, PVarData(Data)^); // !! Untested
|
||||||
end;
|
end;
|
||||||
except
|
except
|
||||||
On E : Exception do
|
On E : Exception do
|
||||||
|
61
tests/test/units/variants/tvararrayofintf.pp
Normal file
61
tests/test/units/variants/tvararrayofintf.pp
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
|
||||||
|
// Tests storing interfaces in VariantArray
|
||||||
|
{$ifdef fpc}{$mode objfpc}{$h+}{$endif}
|
||||||
|
{$apptype console}
|
||||||
|
|
||||||
|
uses sysutils, variants;
|
||||||
|
|
||||||
|
type
|
||||||
|
ITag = interface(IInterface)['{26EBC417-D394-4561-906A-202F32A919EA}']
|
||||||
|
function GetTag: Integer;
|
||||||
|
end;
|
||||||
|
|
||||||
|
tmyobj=class(TInterfacedObject,ITag)
|
||||||
|
private
|
||||||
|
FTag: Integer;
|
||||||
|
function GetTag: Integer;
|
||||||
|
public
|
||||||
|
constructor Create(aTag: Integer);
|
||||||
|
destructor Destroy; override;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
FreeCount: Integer;
|
||||||
|
|
||||||
|
constructor tmyobj.create(aTag: Integer);
|
||||||
|
begin
|
||||||
|
inherited Create;
|
||||||
|
FTag:=aTag;
|
||||||
|
end;
|
||||||
|
|
||||||
|
destructor tmyobj.destroy;
|
||||||
|
begin
|
||||||
|
writeln('Destroy: ', FTag);
|
||||||
|
Inc(FreeCount);
|
||||||
|
inherited;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function tmyobj.gettag: integer;
|
||||||
|
begin
|
||||||
|
result:=FTag;
|
||||||
|
end;
|
||||||
|
|
||||||
|
var
|
||||||
|
values: Variant;
|
||||||
|
i: Integer;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Values := VarArrayCreate([0, 4], varUnknown);
|
||||||
|
for i := 0 to 4 do
|
||||||
|
Values[i] := tmyobj.Create(i) as IInterface;
|
||||||
|
for i := 0 to 4 do
|
||||||
|
begin
|
||||||
|
if (IInterface(Values[i]) as ITag).GetTag <> i then
|
||||||
|
Halt(i);
|
||||||
|
end;
|
||||||
|
FreeCount := 0;
|
||||||
|
Values := 0;
|
||||||
|
writeln(FreeCount);
|
||||||
|
// check for correct number of destroyed objects won't work because one of them
|
||||||
|
// is released after this point.
|
||||||
|
end.
|
Loading…
Reference in New Issue
Block a user