Thanks very much Liu,
This fix eliminates the error.
For your intrest: I modified the script in such a way that, when the script is called on an empty line, the text is inserted at the current cursor position. This makes more sence if you are inserting the version string in a comment block before or after some Delphi source code.
Is there any documentation on the "CnOta..."routines ?
Erik
{*******************************************************}
{ }
{ Pascal Script Source File }
{ Run by RemObjects Pascal Script in CnWizards }
{ }
{ Generated by CnPack IDE Wizards }
{ }
{ Script created by : }
{ - Erik De Laet - E.De.L.Com bvba }
{ 'Programmer by choice and profession!' }
{
www.edelcom.be - Belgium }
{ }
{ Thanks to Passion (LiuXiao) of the CnPack team }
{ for the necessary and appreciated help and }
{ insight in the CnPack routines. }
{ }
{*******************************************************}
program edlInsetVersionInfo;
uses
Windows, SysUtils, CnWizUtils;
var
EditView: IOTAEditView;
Options: IOTAProjectOptions;
Project: IOTAProject;
MajorVer, MinorVer, ReleaseNo, BuildNo: Integer;
sVersion: string;
iColInSource,iCol,iLine : integer;
sFiller: string;
i: integer;
begin
Options := CnOtaGetActiveProjectOptions(nil);
if Options = nil then Exit;
Project := CnOtaGetCurrentProject;
if Project = nil then Exit;
EditView := CnOtaGetTopMostEditView(Nil);
if EditView = Nil then Exit;
// Get the Versions
MajorVer := Options.GetOptionValue('MajorVersion');
MinorVer := Options.GetOptionValue('MinorVersion');
ReleaseNo := Options.GetOptionValue('Release');
BuildNo := Options.GetOptionValue('Build');
// build string to insert
sVersion := '//!' + IntToStr(MajorVer) + '.' + IntToStr(MinorVer) + '.' + IntToStr(ReleaseNo) + '.' + IntToStr(BuildNo);
// get and keep de current cursor position
IdeEditorGetEditPos(iColInSource,iLine);
// move to end of line
EditView.GetPosition.MoveEOL;
// get current position again
IdeEditorGetEditPos(iCol,iLine);
if iCol = 1
then begin
// if we are at the beginning of the line, the line was empty, so insert
// the text at the saved position (by inserting spaces - see note below)
sFiller := '';
for i := 1 to iColInSource-1 do
sFiller := sFiller + ' ';
// we cannot use "IdeEditorGotoEditPos" because this takes a third parameter
// and this will move the current line to the top or the middle of the
// editor window (don't know why this third parameter is needed ???)
// IdeEditorGotoEditPos(iColInSource,iLine,True);
end
else begin
// else try to position the text right aligned at 80 chars (unless we don't
// have room there, in which case the text is inserted after the line
sFiller := '';
if iCol + Length(sVersion) < 80
then begin
for i := 1 to 80-Length(sVersion)-iCol+1 do
sFiller := sFiller + ' ';
end;
end;
// insert the text (including the filler)
IdeInsertTextIntoEditor(sFiller+sVersion);
end.