End

TParamConst = class public

76 You can also specify the constructor constraint without the class constraint, as the former probably implies the latter. Listing both of them makes the code more readable.

Value: Integer;

constructor Create (I: Integer); // set Value to I

end;

As I mentioned earlier, in theory you should be able to use only the first class, while in practice you can use both: var constructObj: TConstrClass<TSimpleCost>; paramCostObj: TConstrClass<TParamCost>; begi n constructObj := TConstrClass<TSimpleCost>.Create; Log ('Value l: ' + IntToStr (constructObj.Get.Value));

paramCostObj := TConstrClass<TParamCost>.Create; Log ('Value 2: ' + IntToStr (paramCostObj.Get.Value));

The output of this code is:

In fact, the second object is never initialized. If you debug the application trace into the code you'll see a call to TObject.Create (which I consider wrong). Notice that if you try calling directly: | with TParamConst.Create do the compiler will (correctly) raise the error77: | [DCC Error] E2035 Not enough actual parameters

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