C++Builder  |  Delphi  |  FireMonkey  |  C/C++  |  Free Pascal  |  Firebird
볼랜드포럼 BorlandForum
 경고! 게시물 작성자의 사전 허락없는 메일주소 추출행위 절대 금지
분야별 포럼
C++빌더
델파이
파이어몽키
C/C++
프리파스칼
파이어버드
볼랜드포럼 홈
헤드라인 뉴스
IT 뉴스
공지사항
자유게시판
해피 브레이크
공동 프로젝트
구인/구직
회원 장터
건의사항
운영진 게시판
회원 메뉴
북마크
볼랜드포럼 광고 모집

자유게시판
세상 살아가는 이야기들을 나누는 사랑방입니다.
[12611] Re:델파이 코드 리팩토링 문제(다 함께 풀어 봅시다)
사악신 [galahan] 2212 읽음    2007-01-05 17:07
그냥, 저도 쓸 일이 있을 것 같아서 조금 범용으로 설계를 해봤는데요.
조금 긴 것 같아서 답변글로 답니다. 나중에 시간나면 적당히 손봐서 개인적으로 사용해보려구요. ^^

1. 사용하고자 하는 유닛에서 다음처럼 호출
:: 초기화시 사용해도 되고 필요시 동적으로 달고 싶은 놈만 다는 형태로 사용...

procedure TFormFileFilter.ButtonOpenClick(Sender: TObject);
var
  Filters : TStringList;
begin
  Filters := TStringList.Create;
  try
    Filters := TDecoratorImageAll.Create( Filters );
    Filters := TDecoratorHWP.Create( Filters );
    Filters := TDecoratorExcel.Create( Filters );
    Filters := TDecoratorPDF.Create( Filters );

    OpenDialog.Filter := Filters.Text;
    if OpenDialog.Execute then
    begin
      //
    end;
  finally
    Filters.Free;
  end;
end;

2. 데코레이터 소스
:: BDS 에서 지원하는 투게더가 좀 미흡한 관계로(오류가 많습니다. ㅡㅡ) 생산성은 조금 떨어지지만,
잘 활용하면 코드량에 비해서 그렇게 많은 시간이 들어가지 않습니다. ^^
델파이 하위 버전과의 호환성을 위하여 추가된 문법들은 정리하여 제거하였습니다.
해당 문서의 검사루틴은 생략했습니다. 각자 적당한 방법으로 채우거나 구조를 활용하면 되지 않을까 싶어서...
아무튼 구조만 잡아봤습니다.

unit FileFilter.Classes.Documents; // BDS 이전 Delphi 7 이하 버전에서는 네임스페이스를 지원하지 않습니다.

interface

uses
  Classes;

type
  TDecoratorDoc = class(TStringList)
  protected
    FComponent: TStringList;

    function GetDoc: String; virtual; abstract;
  public
    constructor Create(ADecorateMe: TStringList);
    destructor Destroy; override;

    function GetTextStr: String; override;
  end;

  TDecoratorImageAll = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorHWP = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorExcel = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorWord = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorPPT = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorPDF = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorPS = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

  TDecoratorEPS = class(TDecoratorDoc)
  protected
    function GetDoc: String; override;
  end;

implementation


{ TDecoratorDoc }

constructor TDecoratorDoc.Create(ADecorateMe: TStringList);
begin
  inherited Create;

  FComponent := ADecorateMe;
end;


destructor TDecoratorDoc.Destroy;
begin
  FComponent.Free;
  FComponent := nil;

  inherited;
end;

function TDecoratorDoc.GetTextStr: String;
var
  Temp: String;
begin
  Temp := inherited GetTextStr;

  Temp := Temp + FComponent.Text + GetDoc;
  Result := Temp;
end;

{ TDecoratorHWP }

function TDecoratorHWP.GetDoc: String;
begin
  Result := 'HWP Document(*.hwp)|*.hwp|';
  try
    // 검사루틴...
  except
    Result := '';
  end;
end;


{ TDecoratorExcel }

function TDecoratorExcel.GetDoc: String;
begin
  Result := 'MS-Excel(*.xls)|*.xls|';
  try
    // 검사루틴...
  except
    Result := '';
  end;
end;


{ TDecoratorImageAll }

function TDecoratorImageAll.GetDoc: String;
begin
  Result := 'Image All(*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.pcx;*.tif;*.tiff;*.psd;*.pdd)|*.jpg;*.jpeg;*.gif;*.png;*.bmp;*.pcx;*.tif;*.tiff;*.psd;*.pdd|';
end;


{ TDecoratorPPT }

function TDecoratorPPT.GetDoc: String;
begin
  Result := 'PowerPoint(*.ppt)|*.ppt|';
  try
    // 검사루틴...
  except
    Result := '';
  end;
end;


{ TDecoratorWord }

function TDecoratorWord.GetDoc: String;
begin
  Result := 'MS-Word(*.doc)|*.doc|';
  try
    // 검사루틴...
  except
    Result := '';
  end;
end;


{ TDecoratorPDF }

function TDecoratorPDF.GetDoc: String;
begin
  Result := 'Adobo PDF File(*.pdf)|*.pdf|';
  try
    // 검사루틴...
  except
    Result := '';
  end;
end;


{ TDecoratorPS }

function TDecoratorPS.GetDoc: String;
begin
  Result := 'PostScript(*.ps)|*.ps|';
  try
    // 검사루틴...
  except
    Result := '';
  end;

end;


{ TDecoratorEPS }

function TDecoratorEPS.GetDoc: String;
begin
  Result := 'Encapsulated PostScript(*.eps)|*.eps|';
  try
    // 검사루틴...
  except
    Result := '';
  end; 
end;

end.

3. 끝으로...
제가 소스 가지고 이런 짓(?)을 자주 합니다.ㅡㅡ 다른 분들 보기에 흉할수도 있겠네요.
아무튼,  정섭님의 리팩토링 소스도 꼭 보고싶습니다. ^^/

+ -

관련 글 리스트
12602 델파이 코드 리팩토링 문제(다 함께 풀어 봅시다) 주정섭 5034 2007/01/04
12622     Re:델파이 코드 리팩토링 문제(다 함께 풀어 봅시다) 주정섭 2566 2007/01/08
12611     Re:델파이 코드 리팩토링 문제(다 함께 풀어 봅시다) 사악신 2212 2007/01/05
Google
Copyright © 1999-2015, borlandforum.com. All right reserved.