[fpc-pascal] with in classes/records

Ryan Joseph ryan at thealchemistguild.com
Tue Sep 4 08:57:42 CEST 2018


I started in on this already and here’s the first conflict I found when trying operators.

What should happen if you assign a record to another record with a default property? 

var
	wrapper: TWrapper;
	other: TWrapper;

// this should assign to ‘obj’ via the default property
wrapper := TObject.Create;

// what happens here? is this a wrong type error (TObject is expected but got TWrapper) or do we assign directly to the base record? I can see it both ways so I’m not sure what principle to fall back on. Allow it because we can or prevent it because it’s not intended functionality?
wrapper := other;

type
	TWrapper = record
		obj: TObject;
		property _default: TObject read obj write obj; default;
		class operator + (left: TWrapper; right: integer): TWrapper;
	end;

class operator TWrapper.+ (left: TWrapper; right: integer): TWrapper;
begin
	// error here
	result := left;
end;



Regards,
	Ryan Joseph




More information about the fpc-pascal mailing list