[fpc-pascal] with in classes/records

Ryan Joseph ryan at thealchemistguild.com
Fri Oct 5 07:03:05 CEST 2018



> On Oct 4, 2018, at 9:19 PM, Michael Van Canneyt <michael at freepascal.org> 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



More information about the fpc-pascal mailing list