Duallist.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:5k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. {*******************************************************}
  2. {                                                       }
  3. {         Delphi VCL Extensions (RX)                    }
  4. {                                                       }
  5. {         Copyright (c) 1995, 1996 AO ROSNO             }
  6. {                                                       }
  7. {*******************************************************}
  8. unit DualList;
  9. interface
  10. {$I RX.INC}
  11. uses Classes, Controls;
  12. type
  13. { TDualListDialog }
  14.   TDualListDialog = class(TComponent)
  15.   private
  16.     FCtl3D: Boolean;
  17.     FSorted: Boolean;
  18.     FTitle: PString;
  19.     FLabel1Caption: TCaption;
  20.     FLabel2Caption: TCaption;
  21.     FOkBtnCaption: TCaption;
  22.     FCancelBtnCaption: TCaption;
  23.     FHelpBtnCaption: TCaption;
  24.     FHelpContext: THelpContext;
  25.     FList1: TStrings;
  26.     FList2: TStrings;
  27.     FShowHelp: Boolean;
  28.     function GetTitle: string;
  29.     procedure SetTitle(const ATitle: string);
  30.     procedure SetList1(Value: TStrings);
  31.     procedure SetList2(Value: TStrings);
  32.     function IsLabel1Custom: Boolean;
  33.     function IsLabel2Custom: Boolean;
  34.     function IsOkBtnCustom: Boolean;
  35.     function IsCancelBtnCustom: Boolean;
  36.     function IsHelpBtnCustom: Boolean;
  37.   public
  38.     constructor Create(AOwner: TComponent); override;
  39.     destructor Destroy; override;
  40.     function Execute: Boolean;
  41.   published
  42.     property Ctl3D: Boolean read FCtl3D write FCtl3D default True;
  43.     property Sorted: Boolean read FSorted write FSorted;
  44.     property Title: string read GetTitle write SetTitle;
  45.     property Label1Caption: TCaption read FLabel1Caption write FLabel1Caption
  46.       stored IsLabel1Custom;
  47.     property Label2Caption: TCaption read FLabel2Caption write FLabel2Caption
  48.       stored IsLabel2Custom;
  49.     property OkBtnCaption: TCaption read FOkBtnCaption write FOkBtnCaption
  50.       stored IsOkBtnCustom;
  51.     property CancelBtnCaption: TCaption read FCancelBtnCaption write FCancelBtnCaption
  52.       stored IsCancelBtnCustom;
  53.     property HelpBtnCaption: TCaption read FHelpBtnCaption write FHelpBtnCaption
  54.       stored IsHelpBtnCustom;
  55.     property HelpContext: THelpContext read FHelpContext write FHelpContext;
  56.     property List1: TStrings read FList1 write SetList1;
  57.     property List2: TStrings read FList2 write SetList2;
  58.     property ShowHelp: Boolean read FShowHelp write FShowHelp default True;
  59.   end;
  60. implementation
  61. uses SysUtils, Forms, FDualLst, Consts, RxTConst, VCLUtils;
  62. { TDualListDialog }
  63. constructor TDualListDialog.Create(AOwner: TComponent);
  64. begin
  65.   inherited Create(AOwner);
  66.   FCtl3D := True;
  67.   FShowHelp := True;
  68.   FTitle := NullStr;
  69.   FList1 := TStringList.Create;
  70.   FList2 := TStringList.Create;
  71.   FLabel1Caption := LoadStr(SDualListSrcCaption);
  72.   FLabel2Caption := LoadStr(SDualListDestCaption);
  73.   OkBtnCaption := ResStr(SOKButton);
  74.   CancelBtnCaption := ResStr(SCancelButton);
  75.   HelpBtnCaption := ResStr(SHelpButton);
  76. end;
  77. destructor TDualListDialog.Destroy;
  78. begin
  79.   List1.Free;
  80.   List2.Free;
  81.   DisposeStr(FTitle);
  82.   inherited Destroy;
  83. end;
  84. function TDualListDialog.GetTitle: string;
  85. begin
  86.   Result := FTitle^;
  87. end;
  88. procedure TDualListDialog.SetTitle(const ATitle: string);
  89. begin
  90.   AssignStr(FTitle, ATitle);
  91. end;
  92. procedure TDualListDialog.SetList1(Value: TStrings);
  93. begin
  94.   FList1.Assign(Value);
  95. end;
  96. procedure TDualListDialog.SetList2(Value: TStrings);
  97. begin
  98.   FList2.Assign(Value);
  99. end;
  100. function TDualListDialog.IsLabel1Custom: Boolean;
  101. begin
  102.   Result := CompareStr(Label1Caption, LoadStr(SDualListSrcCaption)) <> 0;
  103. end;
  104. function TDualListDialog.IsLabel2Custom: Boolean;
  105. begin
  106.   Result := CompareStr(Label2Caption, LoadStr(SDualListDestCaption)) <> 0;
  107. end;
  108. function TDualListDialog.IsOkBtnCustom: Boolean;
  109. begin
  110.   Result := CompareStr(OkBtnCaption, ResStr(SOKButton)) <> 0;
  111. end;
  112. function TDualListDialog.IsCancelBtnCustom: Boolean;
  113. begin
  114.   Result := CompareStr(CancelBtnCaption, ResStr(SCancelButton)) <> 0;
  115. end;
  116. function TDualListDialog.IsHelpBtnCustom: Boolean;
  117. begin
  118.   Result := CompareStr(HelpBtnCaption, ResStr(SHelpButton)) <> 0;
  119. end;
  120. function TDualListDialog.Execute: Boolean;
  121. var
  122.   Form: TDualListForm;
  123. begin
  124.   Form := TDualListForm.Create(Application);
  125.   try
  126.     with Form do begin
  127.       Ctl3D := Self.Ctl3D;
  128. {$IFDEF WIN32}
  129.       if NewStyleControls then Font.Style := [];
  130. {$ENDIF}
  131.       ShowHelp := Self.ShowHelp;
  132.       SrcList.Sorted := Sorted;
  133.       DstList.Sorted := Sorted;
  134.       SrcList.Items := List1;
  135.       DstList.Items := List2;
  136.       if Self.Title <> '' then Form.Caption := Self.Title;
  137.       if Label1Caption <> '' then SrcLabel.Caption := Label1Caption;
  138.       if Label2Caption <> '' then DstLabel.Caption := Label2Caption;
  139.       OkBtn.Caption := OkBtnCaption;
  140.       CancelBtn.Caption := CancelBtnCaption;
  141.       HelpBtn.Caption := HelpBtnCaption;
  142.       HelpContext := Self.HelpContext;
  143.       HelpBtn.HelpContext := HelpContext;
  144.     end;
  145.     Result := (Form.ShowModal = mrOk);
  146.     if Result then begin
  147.       List1 := Form.SrcList.Items;
  148.       List2 := Form.DstList.Items;
  149.     end;
  150.   finally
  151.     Form.Free;
  152.   end;
  153. end;
  154. end.