[fpc-devel] "Default" discussion for SmartPointers etc
Sven Barth
pascaldragon at googlemail.com
Wed Jul 27 22:47:09 CEST 2016
Am 27.07.2016 21:04 schrieb "Maciej Izak" <hnb.code at gmail.com>:
>
>
> 2016-07-27 15:33 GMT+02:00 Jonas Maebe <jonas.maebe at elis.ugent.be>:
>>
>> It would seem better to me that you do have to add something after your
proxy object (specify a field, call a method, use proxyobject[x], ...) to
get the proxied value. Just like with a class, where "instance" by itself
can never refer to the default property (it's always "instance[x]").
>
>
> In that case SmartPtr/SmartObj/Nullable type has no sense for me. The
basic purpose is excluded. You can do that today by using for example
proxyobject._.foo();
>
> To get rid of @@/@@@ we can use typecast + new type kind. With "proxy"
type, Sven proposition has more sense:
>
> === code begin ===
> {$MODE DELPHI}
>
> type
> TRawSomeSmart<T> = record
> private
> Instance: T;
> ... // normal record
> end;
>
> TSomeSmart<T> = proxy to TRawSomeSmart<T>.Instance;
>
> var
> ptr: pointer;
> // PTypeInfo(TypeInfo(ni)).Kind = tkProxy
> ni: TSomeSmart<Integer>;
> np: TSomeSmart<TProcedure>;
> begin
> ptr := @ni; // pointer to ni.Instance
> ptr := @TSomeSmart<Integer>(ni); // pointer to ni
>
> ptr := @@np; // pointer to np.Instance
> ptr := @np // pointer to procedure
> ptr := @TSomeSmart<TProcedure>(np); // pointer to np
> end;
> === code end ===
Hmm, not that bad either. At least then it would be absolutely clear that
TSomeSmart is something special and not an ordinary record.
Regards,
Sven
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160727/37bafd58/attachment.html>
More information about the fpc-devel
mailing list