About the author
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: string); destructor Destroy; override; end; function SiteName(MethodName: string): ISiteName; begin Result := TSiteName.Create(MethodName); end; procedure DebugWriteLine(S: string); begin {$IF DEFINED(CLR)} WriteLn(S); // Debug.Write(S); {$ELSEIF DEFINED(MSWINDOWS)} WriteLn(S); // OutputDebugString(PChar(S)); {$IFEND} end; constructor TSiteName.Create(MethodName: string); begin inherited Create; FMethodName := MethodName; DebugWriteLine('Enter '+FMethodName); end; destructor TSiteName.Destroy; begin DebugWriteLine('Leave '+FMethodName); inherited; end; procedure Test; var I: Integer; begin SiteName('Test'); for I := 1 to 10 do DebugWriteLine(IntToStr(I)); end; begin Test; end.
How to free more space on your home drive by redirecting the location for SDKs in RAD Studio