Menu

[r2509]: / trunk / Src / Help / HTML / snippet_class.htm  Maximize  Restore  History

Download this file

126 lines (122 with data), 3.9 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<!--
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/
*
* Copyright (C) 2012, Peter Johnson (www.delphidabbler.com).
*
* $Rev$
* $Date$
*
* Help topic describing class and advanced record snippet kind.
-->
<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 &amp; 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>
<strong class="warning">Warning:</strong> It is an error to use this
snippet kind for records or classes that have no methods &ndash; use <a
href="snippet_type.htm"
>simple type definition</a> instead. It is also an error to define 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>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.