Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between types defined in the implementation as compared to the interface section of a unit?

Tags:

delphi

Almost all of the Delphi code I have read has all the class type definitions in the units interface section, but I have seen occasional use of type definitions within the implementation section.

What exactly is the difference between these, and why would I use this?

like image 714
HMcG Avatar asked Nov 01 '09 21:11

HMcG


2 Answers

It's pretty simple: types defined in implementation only are only visible within the implementation, so they cannot be used as types of arguments or return values in the interface. So, position your type definitions (like anything else;-) based on whether those types are only an implementation detail, or something you want to make visible externally, i.e., through the interface!

like image 103
Alex Martelli Avatar answered Oct 08 '22 16:10

Alex Martelli


Scope. Interface declarations are public and availabe to other units when that unit is include in the Uses clause. Implementation declarations are private and only available within that specific Unit.

like image 23
Michael Riley - AKA Gunny Avatar answered Oct 08 '22 17:10

Michael Riley - AKA Gunny