Delphi Programming Forum
C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
델파이 포럼
Q & A
FAQ
팁&트릭
강좌/문서
자료실
컴포넌트/라이브러리
FreePascal/Lazarus
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
델마당
볼랜드포럼 광고 모집

델파이 Q&A
Delphi Programming Q&A
[14622] Collection 내의 TStrings은 Code Editor사용할수 없나요?
nobig4 [nobig4] 2517 읽음    2013-03-08 15:33
소스내에 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.
- 끝 -

+ -

관련 글 리스트
14622 Collection 내의 TStrings은 Code Editor사용할수 없나요? nobig4 2517 2013/03/08
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.