Mega Code Archive

 
Categories / Delphi / OOP
 

Accessing protected methods and properties out of context

Title: Accessing protected methods and properties out of context. Question: Some times while developping a form it would be nice or it would be essential to have acces right away to protected methods and properties. Of course you can build a derived component that just publishes the methods you need. But for a single method call the overhead that this approach requires is often inapropriate. What can we do instead? Answer: Here is an example. I recently needed for proper operation access to the "change" method of a "spin edit" control (AmpPitchMaxSpinEdit). In the implementation section of the form (TCmnDispAmpSetDlg) I was developping, i simply redeclared the "spin edit" control (THelperSpinEdit). Then I type cast the forms "spin edit" controls to get acces to the method. implementation type THelperSpinEdit=class(TSpinEdit); function ExecuteCmnDispAmpSetDlg(aOwner:TComponent; AmpVelMinMax:TAmpVelMinMax):Boolean; begin with TCmnDispAmpSetDlg.Create(aOwner) do begin try with AmpVelMinMax do begin AmpPitchMaxSpinEdit.Value:=AmpPitchMax; THelperSpinEdit(AmpPitchMaxSpinEdit).Change; .......... Hope this note helps some time!