Accessing outer class attribute from inner struct

Andre Pany via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Aug 28 14:52:58 PDT 2017


Hi,

I build some framework to access Delphi components from D.
Delphi supports property array access "StringGrid1.Columns[2]" 
which is translated in Delphi to a private method call 
"GetColumn(2)".

I need to imitate this behavior in my D code.
Therefore my TCustomGrid class has a inner struct ColumnsArray 
with an opIndex.
While accessing opIndex I need to call a DLL method. Therefore I 
need the "reference" attribute which is available in my 
TCustomGrid via inheritance.

To make my question short:) If ColumnsArray is a class I can 
access the attribute "reference" but not if it is a struct. I 
would rather prefer a struct, but with a struct
it seems I cannot access "reference".

How can I access "reference" from my inner struct?

class TCustomGrid: TCustomPresentedScrollBox
{	
	struct ColumnsArray
	{
		TColumn opIndex(int index)
		{
			int r = getIntegerIndexedPropertyReference(reference, 
"Columns", index);
			return new TColumn(r);
		}
	}
	
	ColumnsArray Columns;
...
}

Kind regards
André


More information about the Digitalmars-d-learn mailing list