⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jvvalidatorseditorform.pas

📁 East make Tray Icon in delphi
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{-----------------------------------------------------------------------------
The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/MPL-1.1.html

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
the specific language governing rights and limitations under the License.

The Original Code is: JvValidatorsEditorForm.PAS, released on 2003-01-01.

The Initial Developer of the Original Code is Peter Th鰎nqvist [peter3 att users dott sourceforge dott net] .
Portions created by Peter Th鰎nqvist are Copyright (C) 2003 Peter Th鰎nqvist.
All Rights Reserved.

Contributor(s):

You may retrieve the latest version of this file at the Project JEDI's JVCL home page,
located at http://jvcl.sourceforge.net

Known Issues:
-----------------------------------------------------------------------------}
// $Id: JvValidatorsEditorForm.pas,v 1.21 2004/12/25 13:20:42 marquardt Exp $

unit JvValidatorsEditorForm;

{$I jvcl.inc}

interface

uses
  SysUtils, Classes,
  Windows, Messages, Graphics, Controls, Forms,
  Dialogs, ComCtrls, ToolWin, StdCtrls, Menus, ActnList, ImgList,
  {$IFDEF COMPILER6_UP}
  DesignEditors, DesignIntf, DesignWindows,
  {$ELSE}
  DsgnIntf, DsgnWnds,
  {$ENDIF COMPILER6_UP}
  JvValidators;

type
  TfrmValidatorsEditor = class(TDesignWindow)
    ToolBar1: TToolBar;
    btnNew: TToolButton;
    btnDelete: TToolButton;
    StatusBar1: TStatusBar;
    lbValidators: TListBox;
    popNew: TPopupMenu;
    alEditor: TActionList;
    acDelete: TAction;
    il16: TImageList;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    acMoveUp: TAction;
    acMoveDown: TAction;
    popForm: TPopupMenu;
    N1: TMenuItem;
    Delete1: TMenuItem;
    N2: TMenuItem;
    MoveUp1: TMenuItem;
    MoveDown1: TMenuItem;
    procedure alEditorUpdate(Action: TBasicAction; var Handled: Boolean);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure acDeleteExecute(Sender: TObject);
    procedure lbValidatorsClick(Sender: TObject);
    procedure acMoveUpExecute(Sender: TObject);
    procedure acMoveDownExecute(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    FValidator: TJvValidators;
    function AddExisting(Validator: TJvBaseValidator): Integer; overload;
    function AddNew(ValidatorClass: TJvBaseValidatorClass): Integer; overload;
    procedure Delete(Index: Integer);
    procedure ClearValidators;
    procedure SelectItem(AObject: TPersistent);
    procedure UpdateItem(Index: Integer);
    procedure UpdateCaption;
    procedure SetValidator(const Value: TJvValidators);
    procedure DoAddNewValidator(Sender: TObject);
    procedure AddValidatorClasses;
  public
    procedure Activated; override;
    {$IFDEF COMPILER6_UP}
    procedure ItemDeleted(const ADesigner: IDesigner; Item: TPersistent); override;
    procedure DesignerClosed(const Designer: IDesigner; AGoingDormant: Boolean); override;
    procedure ItemsModified(const Designer: IDesigner); override;
    {$ELSE}
    procedure ComponentDeleted(Component: IPersistent); override;
    function UniqueName(Component: TComponent): string; override;
    procedure FormClosed(AForm: TCustomForm); override;
    procedure FormModified; override;
    {$ENDIF COMPILER6_UP}
    function GetEditState: TEditState; override;
    property Validator: TJvValidators read FValidator write SetValidator;
  end;

  TJvValidatorEditor = class(TComponentEditor)
  public
    function GetVerb(Index: Integer): string; override;
    function GetVerbCount: Integer; override;
    procedure ExecuteVerb(Index: Integer); override;
  end;

  TJvPropertyValidateProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TJvPropertyToCompareProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  {$IFDEF COMPILER5}

  // since D5 doesn't support interface style published properties,
  // these editors are supplied to make it easier to select a specific interface
  // implementor at design-time
  TJvValidationSummaryProperty = class(TComponentProperty)
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  TJvErrorIndicatorProperty = class(TComponentProperty)
    procedure GetValues(Proc: TGetStrProc); override;
  end;

  {$ENDIF COMPILER5}

implementation

uses
  TypInfo,
  JvErrorIndicator, JvDsgnConsts;

{$R *.dfm}

procedure ShowEditor(Designer: IDesigner; AValidator: TJvValidators);
var
  I: Integer;
  AEditor: TfrmValidatorsEditor;
begin
  // because the page list editor is not show modal, so
  // we need to find it rather than create a new instance.
  AEditor := nil;
  for I := 0 to Screen.FormCount - 1 do
    if Screen.Forms[I] is TfrmValidatorsEditor then
      if TfrmValidatorsEditor(Screen.Forms[I]).Validator = AValidator then
      begin
        AEditor := TfrmValidatorsEditor(Screen.Forms[I]);
        Break;
      end;
  // Show the wizard editor
  if Assigned(AEditor) then
  begin
    AEditor.Show;
    if AEditor.WindowState = wsMinimized then
      AEditor.WindowState := wsNormal;
  end
  else
  begin
    AEditor := TfrmValidatorsEditor.Create(Application);
    try
      {$IFDEF COMPILER6_UP}
      AEditor.Designer := Designer;
      {$ELSE}
      AEditor.Designer := Designer as IFormDesigner;
      {$ENDIF COMPILER6_UP}
      AEditor.Validator := AValidator;
      AEditor.Show;
    except
      AEditor.Free;
      raise;
    end;
  end;
end;

//=== { TJvValidatorEditor } =================================================

procedure TJvValidatorEditor.ExecuteVerb(Index: Integer);
begin
  if (Index = 0) and (Component is TJvValidators) then
    ShowEditor(Designer, TJvValidators(Component))
  else
    inherited ExecuteVerb(Index);
end;

function TJvValidatorEditor.GetVerb(Index: Integer): string;
begin
  Result := RsJvValidatorsItemsEditorEllipsis;
end;

function TJvValidatorEditor.GetVerbCount: Integer;
begin
  Result := 1;
end;

//== TfrmValidatorsEditor ====================================================

procedure TfrmValidatorsEditor.FormCreate(Sender: TObject);
begin
  AddValidatorClasses;
end;

procedure TfrmValidatorsEditor.Activated;
var
  I: Integer;
begin
  inherited Activated;
  ClearValidators;
  if FValidator = nil then
    Exit;
  lbValidators.Items.BeginUpdate;
  try
    for I := 0 to FValidator.Count - 1 do
      AddExisting(FValidator.Items[I]);
  finally
    lbValidators.Items.EndUpdate;
    lbValidators.ItemIndex := 0;
  end;
end;

function TfrmValidatorsEditor.GetEditState: TEditState;
begin
  Result := [];
end;

{$IFDEF COMPILER6_UP}

procedure TfrmValidatorsEditor.DesignerClosed(const Designer: IDesigner;
  AGoingDormant: Boolean);
begin
  if Designer = Self.Designer then
    Close;
end;

procedure TfrmValidatorsEditor.ItemDeleted(const ADesigner: IDesigner;
  Item: TPersistent);
var
  I, J: Integer;
begin
  inherited ItemDeleted(ADesigner, Item);
  if not (csDestroying in ComponentState) then
  begin
    if Item = Validator then
    begin
      Validator := nil;
      ClearValidators;
      Close;
    end
    else
      for I := 0 to lbValidators.Items.Count - 1 do
        if Item = lbValidators.Items.Objects[I] then
        begin
          J := lbValidators.ItemIndex;
          lbValidators.Items.Delete(I);
          if lbValidators.ItemIndex < 0 then
            lbValidators.ItemIndex := J;
          if lbValidators.ItemIndex < 0 then
            lbValidators.ItemIndex := J - 1;
          Exit;
        end;
    UpdateCaption;
  end;
end;

procedure TfrmValidatorsEditor.ItemsModified(const Designer: IDesigner);
begin
  inherited ItemsModified(Designer);
  if not (csDestroying in ComponentState) then
  begin
    UpdateItem(lbValidators.ItemIndex);
    UpdateCaption;
  end;
end;

{$ELSE}

procedure TfrmValidatorsEditor.ComponentDeleted(Component: IPersistent);
var
  Item: TPersistent;
  I, J: Integer;
begin
  inherited ComponentDeleted(Component);
  Item := ExtractPersistent(Component);
  if not (csDestroying in ComponentState) then
  begin
    if Item = Validator then
    begin
      Validator := nil;
      ClearValidators;
      Close;
    end
    else
      for I := 0 to lbValidators.Items.Count - 1 do
        if Item = lbValidators.Items.Objects[I] then
        begin
          J := lbValidators.ItemIndex;
          lbValidators.Items.Delete(I);
          if lbValidators.ItemIndex < 0 then
            lbValidators.ItemIndex := J;
          if lbValidators.ItemIndex < 0 then
            lbValidators.ItemIndex := J - 1;
          Exit;
        end;
    UpdateCaption;
  end;
end;

procedure TfrmValidatorsEditor.FormClosed(AForm: TCustomForm);
begin
  inherited FormClosed(AForm);
  if AForm = Designer.Form then
    Close;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -