[fpc-devel] "Default" discussion for SmartPointers etc

Maciej Izak hnb.code at gmail.com
Wed Jul 27 21:04:24 CEST 2016

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

To get rid of @@/@@@ we can use typecast + new type kind. With "proxy"
type, Sven proposition has more sense:

=== code begin ===

  TRawSomeSmart<T> = record
    Instance: T;
    ... // normal record

  TSomeSmart<T> = proxy to TRawSomeSmart<T>.Instance;

  ptr: pointer;
  // PTypeInfo(TypeInfo(ni)).Kind = tkProxy
  ni: TSomeSmart<Integer>;
  np: TSomeSmart<TProcedure>;
  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
=== code end ===

Best regards,
Maciej Izak
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20160727/da657986/attachment.html>

More information about the fpc-devel mailing list