You are not logged in.
Pages: 1
I need make a class that expose a published property called Params.
I would like that this property as Variant with latebinding.
How I can do this?
v := TMyClasse.Create;
with Variant(v.Params^) do // this works, but i dislike have to use pointer
begin
Codigo := 10;
Nome := 'Teste de acéntúàção';
Data := StrToDate('18/09/1976');
Valor := 1254.96;
end;
// v.Params = {"Codigo":10,"Nome":"Teste de acéntúàção ","Data":"1976-09-18","Valor":1254.96}
with v.Params do // <<<< how make this way (using Params: Variant)???????????
begin
Codigo := 10;.Codigo := 10;
Nome := 'Teste de acéntúàção';
Data := StrToDate('18/09/1976');
Valor := 1254.96;
end;
// v.Params = {}
how should be my class?????
In this moment it use pointer. how return variant latebinding? or other thing to can use latebinding????
TMyClasse = class
private
FParams: Variant;
function GetParams: Pointer;
public
constructor Create;
property Params: Pointer read GetParams;
end;
...
constructor TMyClasse.Create;
begin
inherited;
TDocVariant.New(FParams, [dvoValueCopiedByReference]);
end;
function TMyClasse.GetParams: Pointer;
begin
Result := @FParams;
end;
Offline
To be honest, I don't expect "with ... do begin ... end" to work with late binding.
It is very confusing for the compiler and human reader.
Whatever solution you would find (like a pointer) just adds confusion.
I won't use late binding for such code, but rather TDocVariantData.Update([]) by name/value pairs.
Perhaps with _Safe().
Offline
To be honest, I don't expect "with ... do begin ... end" to work with late binding.
It is very confusing for the compiler and human reader.
Whatever solution you would find (like a pointer) just adds confusion.I won't use late binding for such code, but rather TDocVariantData.Update([]) by name/value pairs.
Perhaps with _Safe().
You sugestion is something like this?
TMyClasse = class
private
FParams: TDocVariantData;
public
procedure Params(const pName: String; pValue: Variant);
...
constructor TMyClasse.Create;
begin
inherited;
FParams.Init; <<<<<<< _Safe(Need Variant) and return PDocVariant, then I have used .Init. Some problem with this?
end;
procedure TMyClasse.Params(const pName: String; pValue: Variant);
begin
FParams.AddOrUpdateValue(pName, pValue); <<<<<<<<
end;
There are some way to use a property published to use latebiding? If yes, what type should be this property? else thanks AB! I will following this way.
Offline
Pages: 1