<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--
* $Rev$
* $Date$
*
* ***** BEGIN LICENSE BLOCK *****
*
* Version: MPL 1.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
*
* The Original Code is snippet_class.htm
*
* The Initial Developer of the Original Code is Peter Johnson
* (http://www.delphidabbler.com/).
*
* Portions created by the Initial Developer are Copyright (C) 2012 Peter
* Johnson. All Rights Reserved.
*
* ***** END LICENSE BLOCK *****
-->
<html>
<head>
<meta http-equiv="Content-Type" content="text-html; charset=Windows-1252">
<title>
Class and Advanced Record Snippets
</title>
<link rel="stylesheet" href="../css/codesnip.css" type="text/css">
</head>
<body>
<object
type="application/x-oleobject"
classid="clsid:1e2a7bd0-dab9-11d0-b93a-00c04fc99f9e"
>
<param name="ALink Name" value="SnippetClass">
</object>
<h1>
<a name="snippet_class"></a>Class & Advanced Record Snippets
</h1>
<p>
A class (or advanced record) snippet, defines a <em>single</em> Pascal
class or advanced record (i.e. record with methods).
</p>
<p>
The source code must conform to the following rules:
</p>
<ul class="spaced">
<li>
Each snippet must begin with the <strong>type</strong> keyword as the
first non-white-space text in the source code. Comments should not
preceed it. Ideally the <strong>type</strong> keyword should be on a
line on its own.
</li>
<li>
Next follow all the class declarations. Addition <strong>type</strong>
keywords may be used.
</li>
<li>
Method implementations follow once <em>all</em> the class / record types
have been declared. Note that an implementation must be provided for all
classes and record types.
</li>
<li>
The <strong>implementation</strong> keyword must not be used to separate
the declaration and the implementation: <em>CodeSnip</em> works out
where the implementation starts.
</li>
</ul>
<p class="warning">
At present it is an error to use this snippet kind for records or classes
that have no methods. It is also an error to defined more than one class
per snippet.
</p>
<p>
Here are examples valid class and advanced record snippets:
</p>
<p>
Example 1
</p>
<pre class="source-code">type
TMyClass = class(TObject)
private
fField: string;
public
constructor Create(AFoo: string);
function Foo: string;
end;
constructor TMyClass.Create(AFoo: string);
begin
inherited Create;
fField := AFoo;
end;
function TMyClass.Foo: string;
begin
Result := fField;
end;
</pre>
<p>
Example 2
</p>
<pre class="source-code">
type
TPointEx = record
X, Y: Integer;
constructor Create(AX, AY: Integer);
end;
constructor TPointEx.Create(AX, AY: Integer);
begin
X := AX;
Y := AY;
end;</pre>
<p>
Class and Advanced Record snippets may refer to other classes or advanced
records, <a href="snippet_routine.htm">routines</a>,
<a href="snippet_type.htm">simple type definitions</a> or
<a href="snippet_constant.htm">constants</a>, providing they are defined
in Delphi units or elsewhere in the database. The snippet's units and
dependency references should indicate where to find referenced types,
constants and routines. <a href="snippet_freeform.htm">Freeform</a>
and <a href="snippet_unit.htm">unit</a> snippets may not be referenced.
</p>
<p>
It is important that <em>CodeSnip</em> can understand the code because it
must be able to separate the declaration and implementation parts when
generating a unit containing the snippet.
</p>
</body>
</html>