Board index » off-topic » Code Template problem

Code Template problem


2007-10-24 02:56:10 AM
off-topic14
Problem is that point names at the end (starting about 3/4 of the way down)
of the template aren't being replaced. Everything works good for most of the
template.
<?xml version="1.0" encoding="utf-8" ?>
<codetemplate xmlns="schemas.borland.com/Delphi/2005/codetemplates"
version="1.0.0">
<template name="glist" invoke="manual">
<description>
Generic list
</description>
<author>
</author>
<point name="classname">
<text>
classname
</text>
<hint>
Name of new class type
</hint>
</point>
<point name="typename">
<text>
typename
</text>
<hint>
List data type
</hint>
</point>
<code language="Delphi" delimiter="|"><![CDATA[
|classname| = class(TList)
private
fName: string;
fOwner: TObject;
fOwnsObjects: Boolean;
function GetIndexedItem(const Index: Integer): |typename|;
procedure SetIndexedItem(const Index: Integer; Item: |typename|);
function GetNamedItem(const Name: string): |typename|;
procedure SetNamedItem(const Name: string; Item: |typename|);
public
constructor Create; overload;
constructor Create(Owner: TObject); overload;
constructor Create(Owner: TObject; OwnsObjects: Boolean); overload;
destructor Destroy; override;
function Add(Item: |typename|): Integer;
function Extract(Item: |typename|): |typename|;
procedure Delete(Index: Integer);
function Remove(Item: |typename|): Integer;
function IndexOf(Item: |typename|): Integer; overload;
procedure Insert(Index: Integer; Item: |typename|);
function First: |typename|;
function Last: |typename|;
procedure Clear; override;
function GetEnumerator: |classname|Enumerator;
function IndexOf(Name: string): Integer; overload;
procedure WriteToStream(Stream: TRWStream);
procedure ReadFromStream(Stream: TRWStream);
property Name: string read fName write fName;
property Owner: TObject read fOwner write fOwner;
property Items[const Index: Integer]: |typename| read GetIndexedItem write
SetIndexedItem; default;
property Items[const Name: string]: |typename| read GetNamedItem write
SetNamedItem; default;
end;
{ |classname| }
function |classname|.Add(Item: |typename|): Integer;
begin
Result := inherited Add(Item);
end;
function |classname|.IndexOf(Item: |typename|): Integer;
begin
Result := inherited IndexOf(Item);
end;
procedure |classname|.Insert(Index: Integer; Item: |typename|);
begin
inherited Insert(Index, Item);
end;
constructor |classname|.Create;
begin
inherited Create;
fOwnsObjects := TRUE;
end;
constructor |classname|.Create(Owner: TObject);
begin
Create;
fOwner := Owner;
end;
constructor |classname|.Create(Owner: TObject; OwnsObjects: Boolean);
begin
Create(Owner);
fOwnsObjects := OwnsObjects;
end;
procedure |classname|.Clear;
begin
while (Count>0) do
Delete(0);
end;
procedure |classname|.Delete(Index: Integer);
begin
if (fOwnsObjects) then
Items[Index].Free;
inherited;
end;
destructor |classname|.Destroy;
begin
if (fOwnsObjects) then
Clear;
inherited;
end;
function |classname|.Extract(Item: |typename|): |typename|;
begin
Result := |typename|(inherited Extract(Item));
end;
function |classname|.First: |typename|;
begin
Result := |typename|(inherited First);
end;
function |classname|.GetEnumerator: |classname|Enumerator;
begin
Result := |classname|Enumerator.Create(Self);
end;
function |classname|.IndexOf(Name: string): Integer;
var
iIndex: Integer;
begin
Result := -1;
for iIndex := 0 to Count - 1 do begin
if (|typename|(Items[iIndex]).Name = Name) then begin
Result := iIndex;
Exit;
end;
end;
end;
function |classname|.Last: |typename|;
begin
Result := |typename|(inherited Last);
end;
function |classname|.Remove(Item: |typename|): Integer;
begin
Result := inherited Remove(Item);
end;
function |classname|.GetIndexedItem(const Index: Integer): |typename|;
begin
Result := |typename|(Items[Index]);
end;
function |classname|.GetNamedItem(const Name: string): |typename|;
begin
Result := |typename|(Items[IndexOf(Name)]);
end;
procedure |classname|.SetIndexedItem(const Index: Integer; Item:
|typename|);
begin
Items[Index] := Item;
end;
procedure |classname|.SetNamedItem(const Name: string; Item: |typename|);
begin
Items[IndexOf(Name)] := Item;
end;
procedure |classname|.ReadFromStream(Stream: TRWStream);
var
iItem: Integer;
oItem: |typename|;
begin
fName := Stream.ReadString;
iItem := Stream.ReadInteger;
for iItem := 0 to iItem - 1 do begin
oItem := |typename|.Create;
oItem.ReadFromStream(Stream);
Add(oItem);
end;
end;
procedure |classname|.WriteToStream(Stream: TRWStream);
var
iItem: Integer;
begin
Stream.WriteString(fName);
Stream.WriteInteger(Count);
for iItem := 0 to Count - 1 do begin
Stream.WriteString(Items[iItem].ClassName);
Items[iItem].WriteToStream(Stream);
end;
end;
]]>
</code>
</template>
</codetemplate>
 
 

Re:Code Template problem

Rich wrote:
Quote
Problem is that point names at the end (starting about 3/4 of the way
down) of the template aren't being replaced. Everything works good
for most of the template.

I copied the template from your post and replaced the content of a new
template in RAD Studio 2007 with it, saved it and tested it, and it
does work for me. All occurences of the points are replaced OK.
--
Peter Below (TeamB)
Don't be a vampire (slash7.com/pages/vampires),
use the newsgroup archives :
www.tamaracka.com/search.htm
groups.google.com
 

Re:Code Template problem

"Peter Below (TeamB)" <none>wrote in message
Quote

I copied the template from your post and replaced the content of a new
template in RAD Studio 2007 with it, saved it and tested it, and it
does work for me. All occurences of the points are replaced OK.

I just tried that, just in case there was some extraneous characters I
missed. But, that didn't fix it for me, it still leaves |classname| in the
last procedure WriteToStream. Strange.
Anyway, thanks for takin' a look. I'll fiddle with it some more.
 

{smallsort}

Re:Code Template problem

"Peter Below (TeamB)" <none>wrote in message
Quote

I copied the template from your post and replaced the content of a new
template in RAD Studio 2007 with it, saved it and tested it, and it
does work for me. All occurences of the points are replaced OK.

I just copied then pasted from the original unit and it now works fine. I
must of had something hidden in the text I was pasting. I remember pasting
to the template from a unit I was working on not the original unit I keep
the template in.
Thanks again.