소스내에 SQL스크립트 보관하기가 어렵고 외부파일 사용하기도 적절하지 않고 해서
SQL 스크립트를 모아서 필요할때 불러서 사용하기 위해 컴포넌트를 만들어 봤습니다.
스크립트를 저장할 TStrings를 포함한 TCollection으로 구성된 TComponent입니다.
오브젝트 인스펙터에서 TStrings를 편집할때 String List Editor가 나오는데
문제는 String List Editor에서 Code Editor 버튼이 활성화 되지 않습니다.
Collection으로 구성하기 전에는 활성화 되었던것 같은데....
Code Editor 버튼을 활성화 할 방법은 없을까요?
Delphi 7 사용합니다.
전체소스
unit ScriptContainer;
interface
uses
SysUtils, Classes,DB;
type
TScriptBox = class(TComponent)
private
FScript: TStrings;
FNote: String;
procedure SetScript(const Value: TStrings);
public
constructor Create(AOwner:TComponent); override;
destructor Destroy; override;
published
property Note:String read FNote write FNote;
property Script:TStrings read FScript write SetScript;
end;
TScriptItem = class(TNamedItem)
private
FScript: TStrings;
FNote: String;
procedure SetScript(const Value: TStrings);
public
constructor Create(Collection: TCollection); override;
destructor Destroy; override;
published
property Note:String read FNote write FNote;
property Script:TStrings read FScript write SetScript;
end;
TScriptitemClass = class of TScriptItem;
TScriptCollection = class(TCollection)
private
function GetScript(Index: Integer): TScriptItem;
procedure SetScript(Index: Integer; Value: TScriptItem);
protected
procedure Update(Item: TCollectionItem); override;
public
constructor Create(ScriptitemClass: TScriptitemClass);
function Add: TScriptItem;
function Find(const AName: string): TScriptItem;
function IndexOf(const AName: string): Integer;
property Items[Index: Integer]: TScriptItem read GetScript write SetScript; default;
end;
TScriptContainer = class(TComponent)
private
FScriptCollection: TScriptCollection;
procedure SetTScriptCollection(const Value: TScriptCollection);
{ Private declarations }
protected
{ Protected declarations }
public
{ Public declarations }
constructor Create(AOwner:TComponent); override;
destructor Destroy;override;
function ByName(const AName: string): TScriptItem;
published
{ Published declarations }
property Script:TScriptCollection read FScriptCollection write SetTScriptCollection;
end;
procedure Register;
implementation
procedure Register;
begin
RegisterComponents('TEST', [TScriptContainer,TScriptBox]);
end;
{ TScriptContainer }
function TScriptContainer.ByName(const AName: string): TScriptItem;
begin
result:=FScriptCollection.Find(AName);
end;
constructor TScriptContainer.Create(AOwner: TComponent);
begin
inherited;
FScriptCollection:=TScriptCollection.Create(TScriptItem);
end;
destructor TScriptContainer.Destroy;
begin
freeandnil(FScriptCollection);
inherited;
end;
procedure TScriptContainer.SetTScriptCollection(const Value: TScriptCollection);
begin
FScriptCollection := Value;
end;
{ TScriptItem }
constructor TScriptItem.Create(Collection: TCollection);
begin
inherited Create(Collection);
FScript:=TStringList.Create;
end;
destructor TScriptItem.Destroy;
begin
FScript.Free;
inherited;
end;
procedure TScriptItem.SetScript(const Value: TStrings);
begin
FScript.Assign(Value);
end;
{ TScriptCollection }
function TScriptCollection.Add: TScriptItem;
begin
Result := TScriptItem(inherited Add);
end;
constructor TScriptCollection.Create(ScriptitemClass: TScriptitemClass);
begin
inherited Create(ScriptitemClass);
end;
function TScriptCollection.Find(const AName: string): TScriptItem;
var
I: Integer;
begin
I := IndexOf(AName);
if I < 0 then Result := nil else Result := TScriptItem(Items[I]);
end;
function TScriptCollection.GetScript(Index: Integer): TScriptItem;
begin
Result := TScriptItem(inherited Items[Index]);
end;
function TScriptCollection.IndexOf(const AName: string): Integer;
begin
for Result := 0 to Count - 1 do
if AnsiCompareText(TNamedItem(Items[Result]).Name, AName) = 0 then Exit;
Result := -1;
end;
procedure TScriptCollection.SetScript(Index: Integer; Value: TScriptItem);
begin
Items[Index].Assign(Value);
end;
procedure TScriptCollection.Update(Item: TCollectionItem);
begin
inherited;
end;
{ TScriptBox }
constructor TScriptBox.Create(AOwner: TComponent);
begin
inherited;
FScript:=TStringList.Create;
end;
destructor TScriptBox.Destroy;
begin
FScript.Free;
inherited;
end;
procedure TScriptBox.SetScript(const Value: TStrings);
begin
FScript.Assign(Value);
end;
end.
- 끝 -
|