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

📄 dxmdsedt.pas

📁 在Dephi中用于文件的输出
💻 PAS
📖 第 1 页 / 共 2 页
字号:
{*******************************************************************}
{                                                                   }
{       Developer Express Visual Component Library                  }
{       ExpressMemData - CLX/VCL Edition                            }
{                                                                   }
{       Copyright (c) 1998-2008 Developer Express Inc.              }
{       ALL RIGHTS RESERVED                                         }
{                                                                   }
{   The entire contents of this file is protected by U.S. and       }
{   International Copyright Laws. Unauthorized reproduction,        }
{   reverse-engineering, and distribution of all or any portion of  }
{   the code contained in this file is strictly prohibited and may  }
{   result in severe civil and criminal penalties and will be       }
{   prosecuted to the maximum extent possible under the law.        }
{                                                                   }
{   RESTRICTIONS                                                    }
{                                                                   }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES           }
{   (DCU, OBJ, DLL, DPU, SO, ETC.) ARE CONFIDENTIAL AND PROPRIETARY }
{   TRADE SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER}
{   IS LICENSED TO DISTRIBUTE THE EXPRESSMEMDATA                    }
{   AS PART OF AN EXECUTABLE PROGRAM ONLY.                          }
{                                                                   }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED      }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE        }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE       }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT  }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                      }
{                                                                   }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON       }
{   ADDITIONAL RESTRICTIONS.                                        }
{                                                                   }
{*******************************************************************}

unit dxmdsedt;

interface

{$I cxVer.inc}

uses
{$IFDEF DELPHI6}
  DesignIntf,
{$ELSE}
  DsgnIntf,
{$ENDIF}
  Windows, Classes, Controls, Forms, StdCtrls, dxmdaset, ExtCtrls, Menus, Graphics;

type

  {$IFDEF DELPHI6}
    IFormDesigner = IDesigner;
  {$ENDIF}

  TfrmdxMemDataEditor = class(TForm)
  private
    ListBox: TListBox;
    pnButtons: TPanel;
    BAdd: TButton;
    BDelete: TButton;
    BUp: TButton;
    BDown: TButton;
    pmColumns: TPopupMenu;
    miShowButtons: TMenuItem;
    procedure ListBoxClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure BAddClick(Sender: TObject);
    procedure BDeleteClick(Sender: TObject);
    procedure miUpClick(Sender: TObject);
    procedure miDownClick(Sender: TObject);
    procedure miSelectAllClick(Sender: TObject);
    procedure miShowButtonsClick(Sender: TObject);
    procedure ListBoxDragOver(Sender, Source: TObject; X, Y: Integer;
      State: TDragState; var Accept: Boolean);
    procedure ListBoxStartDrag(Sender: TObject;
      var DragObject: TDragObject);
    procedure ListBoxEndDrag(Sender, Target: TObject; X, Y: Integer);
    procedure ListBoxDragDrop(Sender, Source: TObject; X, Y: Integer);

    procedure CreateControls;

    procedure MoveField(ADirection: Integer);
    procedure GetSelection(AList: TList);
    procedure SetSelection(AList: TList);
  protected
  {$IFDEF DELPHI9}
    procedure CreateParams(var Params: TCreateParams); override;
  {$ENDIF}
  public
    Data: TdxMemData;
    FormDesigner: {$IFDEF DELPHI4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF};

    procedure FillList;
  end;

function ShowdxMemDataEditor(AData: TdxMemData; FormDesigner: {$IFDEF DELPHI4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}): Boolean;

implementation

uses
{$IFDEF DELPHI5}
  Contnrs,
{$ENDIF}
  DB, dxmdseda;

var
  FormList: TList;

const
  OldDragIndex: Integer = -1;

type
  TMemDataSetDesigner = class(TDataSetDesigner)
  private
   AForm: TfrmdxMemDataEditor;
   FDestroying: Boolean;
  public
    destructor Destroy; override;
    procedure DataEvent(Event: TDataEvent;
      Info: Longint); override;
  end;

destructor TMemDataSetDesigner.Destroy;
begin
  FDestroying := True;
  if AForm <> nil then
    AForm.Close;
  inherited Destroy;
end;

procedure TMemDataSetDesigner.DataEvent(Event: TDataEvent;
  Info: Longint);
var
  i, j: Integer;
begin
  if AForm <> nil then
    with AForm do
    begin
      ListBox.Items.BeginUpdate;
      for i := 0 to Data.FieldCount - 1 do
        if Data.Fields[i].Owner = Data.Owner then
        begin
          j := ListBox.Items.IndexOfObject(Data.Fields[i]);
          if j > -1 then
            ListBox.Items[j] := Data.Fields[i].FieldName;
        end;
      ListBox.Items.EndUpdate;
    end;
end;

function ShowdxMemDataEditor(AData: TdxMemData; FormDesigner: {$IFDEF DELPHI4}IFormDesigner{$ELSE}TFormDesigner{$ENDIF}): Boolean;
var
  AForm: TfrmdxMemDataEditor;
  i: Integer;
begin
  AForm := nil;
  for i := 0 to FormList.Count - 1 do
    if TfrmdxMemDataEditor(FormList[i]).Data = AData then
    begin
      AForm := TfrmdxMemDataEditor(FormList[i]);
      Break;
    end;
  if AForm = nil then
  begin
    AForm := TfrmdxMemDataEditor.CreateNew(nil {$IFDEF DELPHI4}, 0 {$ENDIF});
    AForm.CreateControls;
    AForm.Data := AData;
    AForm.FormDesigner := FormDesigner;
    TMemDataSetDesigner.Create(AData);
    TMemDataSetDesigner(AData.Designer).AForm := AForm;
    FormList.Add(AForm);
  end;
  with AForm do
  begin
    FillList;
    Caption := 'Editing ' + Data.Name + '.Fields';
    Show;
    Result := True;
  end;
end;

procedure TfrmdxMemDataEditor.FillList;
Var
  i: Integer;
begin
  ListBox.Items.BeginUpdate;
  ListBox.Items.Clear;
  for i := 0 to Data.FieldCount - 1 do
    if Data.Fields[i].Owner = Data.Owner then
      ListBox.Items.AddObject(Data.Fields[i].FieldName, Data.Fields[i]);
  ListBox.Items.EndUpdate;
  ListBoxClick(nil);
end;

{$IFDEF DELPHI5}
  {$IFNDEF DELPHI6}
    {$DEFINE MAKEIPERSISTENT}
  {$ENDIF}
{$ENDIF}

procedure TfrmdxMemDataEditor.ListBoxClick(Sender: TObject);
var
  List: {$IFDEF DELPHI5}IDesignerSelections{$ELSE}TComponentList{$ENDIF};
  i: Integer;
begin
  if (csDesigning in Data.ComponentState) then
  begin
    {$IFDEF DELPHI5}
    List := CreateSelectionList;
    {$ELSE}
    List := TComponentList.Create;
    {$ENDIF}
    try
      for i := 0 to Listbox.Items.Count - 1 do
        if Listbox.Selected[i] then
          List.Add({$IFDEF MAKEIPERSISTENT}MakeIPersistent{$ENDIF}(TComponent(Listbox.Items.Objects[i])));
        if List.Count > 0 then
          FormDesigner.SetSelections(List)
        else
          FormDesigner.SelectComponent(Data);
    finally
    {$IFNDEF DELPHI5}
      List.Free;
    {$ENDIF}
    end;
  end;
  BDelete.Enabled := Listbox.SelCount > 0;
  BUp.Enabled := Listbox.SelCount > 0;
  BDown.Enabled := Listbox.SelCount > 0;
end;

procedure TfrmdxMemDataEditor.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  if (Data <> nil) and Not (csDestroying in Data.ComponentState)
  and (Data.Designer <> nil) and not TMemDataSetDesigner(Data.Designer).FDestroying then
  begin
    TMemDataSetDesigner(Data.Designer).AForm := nil;
    Data.Designer.Free;
  end;
  FormList.Remove(self);
  Action := caFree;
end;

procedure TfrmdxMemDataEditor.BAddClick(Sender: TObject);
var
  AField: TField;
  P: TPoint;
begin
  P := Point(BAdd.Left + BAdd.Width, BAdd.Top);
  P := ClientToScreen(P);
  Data.Close;
  AField := GetMemDataNewFieldType(Data, P.X, P.Y, FormDesigner);
  if AField <> nil then
  begin
    FillList;
    ListBox.Selected[ListBox.Items.Count-1] := True;
    ListBox.ItemIndex := ListBox.Items.Count-1;
    ListBox.SetFocus;
    ListBoxClick(nil);
  end;
end;

procedure TfrmdxMemDataEditor.BDeleteClick(Sender: TObject);
var
  i, OldIndex: Integer;
  List: TList;
begin
  if Data <> nil then
  begin
    OldIndex := ListBox.ItemIndex;
    List := TList.Create;
    for i := 0 to ListBox.Items.Count - 1 do
     if ListBox.Selected[i] then
        List.Add(ListBox.Items.Objects[i]);
    for i := 0 to List.Count - 1 do
       TField(List[i]).Free;
    List.Free;
    FillList;

⌨️ 快捷键说明

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