with in classes/records

classic Classic list List threaded Threaded
44 messages Options
123
Reply | Threaded
Open this post in threaded view
|

Re: with in classes/records

Michael Van Canneyt


On Thu, 4 Oct 2018, Ryan Joseph wrote:

>
>
>> On Sep 26, 2018, at 1:14 AM, Benito van der Zander <[hidden email]> wrote:
>>
>> Hi,
>>
>> perhaps everything would be clearer, if the default property was accessed with ^  ?
>>
>>
>> var
>> wrapper: TWrapper;
>> begin
>> wrapper := TWrapper.Create;
>> wrapper^ := THelperA.Create;
>> end.
>>
>
> Sorry, back to working on this today.
>
> That’s an idea.  Probably the other way around though since initializing
> the class is the less common operation.  The compiler team is busy I guess
> because I haven’t got any answers recently on questions.  I suspect
> appropriating the ^ symbol will not be ok with them since it has another
> reserved meaning.
Technical issues aside, it kind of defeats the purpose of the default
property...

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: with in classes/records

Ryan Joseph-3


> On Oct 4, 2018, at 8:34 PM, Michael Van Canneyt <[hidden email]> wrote:
>
> Technical issues aside, it kind of defeats the purpose of the default
> property...

Then just tolerate the fact we have a dual meaning for assignments? Looks wrong but maybe not a problem.

var
        wrapper: TWrapper;
begin
        wrapper := TWrapper.Create;
        wrapper := THelperA.Create;


Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: with in classes/records

Michael Van Canneyt


On Thu, 4 Oct 2018, Ryan Joseph wrote:

>
>
>> On Oct 4, 2018, at 8:34 PM, Michael Van Canneyt <[hidden email]> wrote:
>>
>> Technical issues aside, it kind of defeats the purpose of the default
>> property...
>
> Then just tolerate the fact we have a dual meaning for assignments? Looks wrong but maybe not a problem.
>
> var
> wrapper: TWrapper;
> begin
> wrapper := TWrapper.Create;
> wrapper := THelperA.Create;

And was this not the whole idea of introducing a default property in the first place ?

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: with in classes/records

Ryan Joseph-3


> On Oct 4, 2018, at 9:19 PM, Michael Van Canneyt <[hidden email]> wrote:
>
> And was this not the whole idea of introducing a default property in the first place ?

It is but I just wanted to make sure that this particular ambiguity with initializing classes wasn’t concerning for anyone.

So far I’ve identified 2 instances where the default needs to be ignored:

1) Assigning the same type i.e. during copies for records or init’ing classes
2) When passing into functions (like in writeln below we need to specify the default property so we don’t try to write the actual class)

Just making sure this is ok.

type
        TWrapper = class
                m_value: integer;
                property value: integer read m_value write m_value; default;
        end;

var
        wrapper: TWrapper;
        i: integer;
begin
        wrapper := TWrapper.Create;
        wrapper := 100;
        wrapper := wrapper + 1;
        writeln(wrapper.value);
        i := wrapper; // error, this passes the class TWrapper
end.

Regards,
        Ryan Joseph

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
123