What is the difference in behaviour in the code shown below in Delphi 7, and Delphi 8? Hint: IInterface and Inheritance (Click if you have Delphi 8 installed). Let's discuss, shall we?
The following code uses a coding habit of mine, which, incidentally, matches with that of Nick as discussed in his “Uses Clauses” article. Great minds think... [I leave that for you to complete ;o) ]
For more interesting usages of interfaces, refer to Malcolm's excellent “Interfaces: Off the Beaten Track” and his blog. Interestingly, I've used Malcolm's trick about a year ago in a VEP project.
{$APPTYPE CONSOLE}
uses
SysUtils
{$IF DEFINED(CLR)}
, System
.
Diagnostics
{$ELSEIF DEFINED(MSWINDOWS)}
, Windows
{
$IFEND
}
;
type
ISiteName =
interface
end
TSiteName =
class
(TInterfacedObject, ISiteName)
private
FMethodName:
string
public
constructor
Create(MethodName:
);
destructor
Destroy; override;
function
SiteName(MethodName:
): ISiteName;
begin
Result := TSiteName
Create(MethodName);
procedure
DebugWriteLine(S:
WriteLn
(S);
// Debug.Write(S);
// OutputDebugString(PChar(S));
TSiteName
inherited
Create;
FMethodName := MethodName;
DebugWriteLine(
'Enter '
+FMethodName);
Destroy;
'Leave '
Test;
var
I:
Integer
SiteName(
'Test'
for
I :=
1
to
10
do
DebugWriteLine(IntToStr(I));