A unit snippet defines a complete Pascal unit. If a unit compiles successfully in Delphi or in Free Pascal then it is valid for use as a unit snippet.
Unit snippets are compilable just like all the other snippet kinds, except freeform. However, that is where the similarities end. Specifically, unit snippets:
Here is an example of a unit snippet:
// A sample unit, adapted from the CodeSnip source code repository
unit UShowCaseCtrl;
interface
uses
Controls;
type
// Simple transparent control designed to be placed over other controls to
// prevent user interaction with the "show cased" controls.
TShowCaseCtrl = class(TCustomControl)
protected
// Modifies window creation parameters. Ensures control is transparent.
procedure CreateParams(var Params: TCreateParams); override;
end;
implementation
uses
Windows;
{ TShowCaseCtrl }
procedure TShowCaseCtrl.CreateParams(var Params: TCreateParams);
begin
inherited;
Params.ExStyle := Params.ExStyle or WS_EX_TRANSPARENT;
end;
end.
In this unit, the Windows and Controls units must be accessible to the available compilers. All is well in this case because the units are in the VCL.
Notes
† For other compilable snippet types the required units are entered in the Snippets Editor, but for unit snippets they are entered in the source code itself.
‡ Compiler search paths can be configured in the Search Paths tab of the Configure Compilers dialogue box.