很簡單的兩個腳本,CnPack的腳本本來是不錯的功能,它為用戶提供一個簡單的平臺,可以實現一些其他CnPack開發人員沒有時間實現,但是可能很實用(面向的人群有局限性)的功能,但是似乎沒有得到多少人的關注,希望能拋磚引玉
。
SQLToString--把當前選擇的SQL腳本轉換為字符串源碼
{*******************************************************}
{ }
{ Pascal Script Source File }
{ Run by RemObjects Pascal Script in CnWizards }
{ }
{ Generated by CnPack IDE Wizards }
{ }
{*******************************************************}
program SQLToString;
uses
Windows, SysUtils, Classes, CnWizIdeUtils;
function DupeString(const AText: string; ACount: Integer): string;
var
i: Integer;
begin
i := ACount;
while i > 0 do
begin
Result := Result + AText;
i := i - 1;
end;
end;
var
Lines: TStringList;
sTemp: string;
i, FirstPos: Integer;
IsDelphi: Boolean;
begin
//IsDelphi := false;
//IsDelphi := Compiler <> cnBCB6;
IsDelphi := WizOptions.CompilerID <> 'CB6';
//WriteLn(WizOptions.CompilerID);
//IsDelphi := Pos('Delphi', Application.MainForm.Caption) > 0;
Lines := TStringList.Create;
try
if IdeGetEditorSelectedLines(Lines) and (Lines.Count > 0) then
begin
i := 1;
sTemp := Lines[0];
while (sTemp[i] = ' ') do
i := i + 1;
FirstPos := i;
for i := 0 to Lines.Count - 1 do
begin
sTemp := Lines[i];
sTemp := Copy(sTemp, FirstPos, Length(sTemp));
if IsDelphi then
sTemp := QuotedStr(sTemp + ' ')
else
begin
sTemp := StringReplace(sTemp, '"', '\"', [rfReplaceAll]);
sTemp := '"' + sTemp + ' \r\n"';
end;
if IsDelphi and (i <> Lines.Count - 1) then
sTemp := sTemp + ' +';
Lines[i] := DupeString(' ', FirstPos - 1) + sTemp;
end;
IdeSetEditorSelectedLines(Lines);
end;
finally
Lines.Free;
end;
end.
[i][i][i]
==================================================================
FormatSrc--簡單的格式化源碼(可以對當前選擇的源碼做一些簡單的處理,美化一下,當然各位可以根據自己需求做更多的優化)
{*******************************************************}
{ }
{ Pascal Script Source File }
{ Run by RemObjects Pascal Script in CnWizards }
{ }
{ Generated by CnPack IDE Wizards }
{ }
{*******************************************************}
program FormatSrc;
uses
Windows, SysUtils, Classes, CnWizIdeUtils;
function DupeString(const AText: string; ACount: Integer): string;
var
i: Integer;
begin
i := ACount;
while i > 0 do
begin
Result := Result + AText;
i := i - 1;
end;
end;
var
Lines: TStringList;
sTemp: string;
i, FirstPos: Integer;
IsDelphi: Boolean;
begin
IsDelphi := WizOptions.CompilerID <> 'CB6';
Lines := TStringList.Create;
try
if IdeGetEditorSelectedLines(Lines) and (Lines.Count > 0) then
begin
for i := 0 to Lines.Count - 1 do
begin
sTemp := Lines[i];
if sTemp = '' then continue;
if sTemp[Length(sTemp)] <> ';' then continue;
while (Length(sTemp) >=2) and (sTemp[Length(sTemp) - 1] = ' ') do
Delete(sTemp, Length(sTemp) - 1, 1);
Lines[i] := sTemp;
end;
IdeSetEditorSelectedLines(Lines);
end;
finally
Lines.Free;
end;
end.[i][/i][/i][/i][/i]
[[i] 本帖最後由 jAmEs_ 於 2009-3-26 16:32 編輯 [/i]]