[fpc-pascal] with in classes/records

Michael Van Canneyt michael at freepascal.org
Mon Sep 3 09:41:52 CEST 2018



On Mon, 3 Sep 2018, Ryan Joseph wrote:

> I’m sorry to bring this one up again but it was touched upon in regards to management operators and auto free objects. Please bear with me while I recap.
>
> I’m writing this email today because I just had this exact same problem in
> my code and I’m desperate to make this work better in Pascal.  :) Making
> auto free work as intended would be amazing also but we need to pass this
> hurdle first.
>
> Thank you for bearing with me, so finally here are my questions:
>
> 1) Given this is critical to make management operators work smoothly what does the compiler team think about this idea to have a default property or “with" in classes/records?

'with' is terribly awkward.

If it needs to be done, please use 'default', it is in line with the default array property.

I suggest you only allow it on properties, not on fields. 
In the case of records, this will automatically imply the use of advanced records, 
and would prohibit it on classical records.

Make sure you establish precedence rules correctly. The default should only be
searched after all other properties/fields were handled.

TA = Class
   B : Integer;
end;

TB = record
Private
   FA : TA;
Public
   Property A : TA Read FA Write FA; default;
   B : Integer;
end;

Var
   C : TB;

begin
   C.B // Must refer to TB.B, not C.A.B
end.

I'm sure there are other pitfalls.

> 2) If there is any plausible way the compiler team will allow this I’m
> willing to develop it myself to what every specification the team decides. 
> I already looked into how this could be implemented and did some tests. 
> It’s not complicated and within the range of something I could accomplish.

Patches are always plausible.

Just dive in and ask questions. Help will surely be provided. 
When you feel you're done, provide a patch. It will be considered like all
other patches.

Michael.


More information about the fpc-pascal mailing list