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

📄 volcoleditor.pas

📁 dephi对Dbgrid控件的显示、控制
💻 PAS
字号:
unit VolColEditor;

interface
uses
  SysUtils, Classes,
  {$IFDEF VER140} DesignIntf, DesignEditors,
{$ELSE}{$IFDEF VER150} DesignIntf, DesignEditors,
  {$ELSE} DsgnIntf, {$ENDIF}
  {$ENDIF}
  ColnEdit, DB, Menus, Dialogs, Controls;

type
  TVolgaDBGridColumnsEditor = class(TCollectionEditor)
  private
    procedure AddAllClick(Sender: TObject);
  protected
    function CanAdd(Index: Integer): Boolean; override;
  public
    mnuAddAll: TMenuItem;
    mnuLine: TMenuItem;
    constructor Create(AOwner: TComponent); override;
  end;

{ TVolgaDBGridColumnsProperty }

  TVolgaDBGridColumnsProperty = class(TClassProperty)
  public
    procedure Edit; override;
    function GetAttributes: TPropertyAttributes; override;
    function GetValue: string; override;
  end;

{ TVolgaDBGridEditor }

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

{ TVolgaColumnDataFieldProperty }

  TVolgaColumnDataFieldProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValueList(List: TStrings); virtual;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

{ TVolgaColumnLookupKeyProperty }

  TVolgaColumnLookupKeyProperty = class(TStringProperty)
  public
    function GetAttributes: TPropertyAttributes; override;
    procedure GetValueList(List: TStrings); virtual;
    procedure GetValues(Proc: TGetStrProc); override;
  end;

implementation
uses VolDBGrid;

{ TVolgaDBGridColumnsProperty }

procedure TVolgaDBGridColumnsProperty.Edit;
begin
  ShowCollectionEditorClass(Designer, TVolgaDBGridColumnsEditor,
    GetComponent(0) as TComponent, TVolgaDBGridColumns(GetOrdValue), GetName);
end;

function TVolgaDBGridColumnsProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paDialog, paReadOnly];
end;

function TVolgaDBGridColumnsProperty.GetValue: string;
begin
  FmtStr(Result, '(%s)', [GetPropType^.Name]);
end;

{ TVolgaDBGridEditor }

procedure TVolgaDBGridEditor.ExecuteVerb(Index: Integer);
begin
  ShowCollectionEditorClass(Designer, TVolgaDBGridColumnsEditor, Component,
    TVolgaDBGrid(Component).Columns, 'Columns');
end;

function TVolgaDBGridEditor.GetVerb(Index: Integer): string;
begin
  Result := '列编辑...';
end;

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

{ TVolgaColumnDataFieldProperty }

procedure TVolgaColumnDataFieldProperty.GetValueList(List: TStrings);
var
  Grid: TVolgaCustomDBGrid;
  DataSource: TDataSource;
begin
  Grid := (GetComponent(0) as VolDBGrid.TVolgaColumn).Grid;
  if (Grid = nil) then Exit;
  DataSource := Grid.DataSource;
  if (DataSource <> nil) and (DataSource.DataSet <> nil)
  and (DataSource.DataSet.FieldCount > 0) then
    DataSource.DataSet.GetFieldNames(List);
end;

function TVolgaColumnDataFieldProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paSortList, paMultiSelect];
end;

procedure TVolgaColumnDataFieldProperty.GetValues(Proc: TGetStrProc);
var
  I: Integer;
  Values: TStringList;
begin
  Values := TStringList.Create;
  try
    GetValueList(Values);
    for I := 0 to Values.Count - 1 do
      Proc(Values[I]);
  finally
    Values.Free;
  end;
end;

{ TVolgaColumnLookupKeyProperty }

procedure TVolgaColumnLookupKeyProperty.GetValueList(List: TStrings);
var
  Column: TVolgaColumn;
begin
  Column := GetComponent(0) as VolDBGrid.TVolgaColumn;
  if (Column = nil) then Exit;
  if (Column.LookupDataSet <> nil) and (Column.LookupDataSet.FieldCount>0) then
    Column.LookupDataSet.GetFieldNames(List);
end;

function TVolgaColumnLookupKeyProperty.GetAttributes: TPropertyAttributes;
begin
  Result := [paValueList, paSortList, paMultiSelect];
end;

procedure TVolgaColumnLookupKeyProperty.GetValues(Proc: TGetStrProc);
var
  I: Integer;
  Values: TStringList;
begin
  Values := TStringList.Create;
  try
    GetValueList(Values);
    for I := 0 to Values.Count - 1 do
      Proc(Values[I]);
  finally
    Values.Free;
  end;
end;

{ TVolgaDBGridColumnsEditor }

constructor TVolgaDBGridColumnsEditor.Create(AOwner: TComponent);
begin
  inherited;
  mnuAddAll := NewItem('添加全部字段', 0, false, true, AddAllClick, 0, 'mnuAddAll');
  PopupMenu1.Items.Add(mnuAddAll);
  mnuAddAll.MenuIndex := 0;
  mnuLine := NewItem('-', 0, false, true, nil, 0, 'mnuLine');
  PopupMenu1.Items.Add(mnuLine);
  mnuLine.MenuIndex := 1;
end;

function TVolgaDBGridColumnsEditor.CanAdd(Index: Integer): Boolean;
begin  //镱赅琨忄屐 蝾朦觐 蝈 觐腩黻

⌨️ 快捷键说明

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