Delphi – Why does a class need an empty method to call it?

I am evaluating an existing dependency injection library for Delphi, and settled on delphidicontainer due to its simplicity-it only requires a unit file!

However, there is one thing I don’t understand – at the bottom of this example file:

initialization
//with those lines the linked will include the actual code for the services
TCSVDataService.Register;
TPaddedDataService.Register;

These Register methods are empty, but if I comment out these two in the initialization section OK, DIContainer.Get(‘dataservice’) will fail as TDataService.

Why? What are these empty methods?

The Delphi compiler is smart and will try to eliminate unused ones when compiling/linking code Code, so from the perspective of the compiler, the implementation class in the example (for example, TCSVDataService) will not be used anywhere in the program and will be deleted, so these empty method calls are to prevent this from happening. /div>

I am evaluating an existing dependency injection library for Delphi, and settled on delphidicontainer due to its simplicity-it only requires a unit file!

However, there is one thing I don’t understand – at the bottom of this example file:

initialization
//with those lines the linked will include the actual code for the services
TCSVDataService.Register;
TPaddedDataService.Register;

These Register methods are empty, but if I comment out these two in the initialization section OK, DIContainer.Get(‘dataservice’) will fail as TDataService.

Why? What are these empty methods?

The Delphi compiler is smart and will try to eliminate unused code when compiling/linking the code, so from the perspective of the compiler, the example The implementation class in (for example, TCSVDataService) will not be used anywhere in the program and will be deleted, so these empty method calls are to prevent this from happening.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3116 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.