End

Notice that while the TGetValue<T> generic class implements the generic IGetValue<T> interface, the TButtonValue specific class implements the IGetValue<Integer> specific interface. Specifically, as in a previous example, the interface is remapped to the Left property of the control:

function TButtonValue.GetValue: Integer; begi n

In the class above, the MakeTButtonValue class function is a ready-to-use method to create an object of the class. This method is used by the third button of the main form, as follows:

procedure TFormGenericInterface.btnValueButtonClick(

Sender: TObject); var iVal: IGetValue<Integer>; begi n iVal := TButtonValue.MakeTButtonValue (

self, ScrollBoxl); Log ('Button value: ' + IntToStr (iVal.GetValue)); end;

Although this is totally unrelated with generic classes, here is the implementation of the MakeTButtonValue class function:

class function TButtonValue.MakeTButtonValue(

Owner: TComponent; Parent: TWinControl): TButtonValue; begi n

Result := TButtonValue.Create(Owner); Result.Parent := Parent; Result.SetBounds(Random (Parent.Width),

Random (Parent.Height), Result.Width, Result.Height); Result.Caption := 'btnv'; end;

Was this article helpful?

0 0
Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook


Post a comment