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

📄 dxmdsedt.pas

📁 在Dephi中用于文件的输出
💻 PAS
📖 第 1 页 / 共 2 页
字号:
    if OldIndex >= ListBox.Items.Count then
      OldIndex := ListBox.Items.Count - 1;
    if (OldIndex <> -1) and (ListBox.Items.Count > 0) then
      ListBox.Selected[OldIndex] := True;
    ListBox.SetFocus;
    ListBoxClick(nil);
  end;
end;

procedure TfrmdxMemDataEditor.miUpClick(Sender: TObject);
begin
  MoveField(-1);
end;

procedure TfrmdxMemDataEditor.miDownClick(Sender: TObject);
begin
  MoveField(1);
end;

procedure TfrmdxMemDataEditor.miSelectAllClick(Sender: TObject);
var
  i: Integer;
begin
  with ListBox do
    for i := 0 to Items.Count - 1 do
      Selected[i] := True;
  ListBox.SetFocus;
  ListBoxClick(nil);
end;

procedure TfrmdxMemDataEditor.miShowButtonsClick(Sender: TObject);
begin
  miShowButtons.Checked := not miShowButtons.Checked;
  pnButtons.Visible := miShowButtons.Checked;
end;

procedure TfrmdxMemDataEditor.ListBoxDragOver(Sender, Source: TObject; X,
  Y: Integer; State: TDragState; var Accept: Boolean);
var
  Index: Integer;
begin
  Accept := Source = ListBox;
  if not Accept then
    Exit;
  Index := ListBox.ItemAtPos(Point(X, Y), True);
  if OldDragIndex <> Index then
  begin
    if OldDragIndex <> -1 then
      ListBox.Selected[OldDragIndex] := False;
    if Index <> -1 then
      if not ListBox.Selected[Index] then
      begin
        ListBox.Selected[Index] := True;
        OldDragIndex := Index;
      end
      else
        OldDragIndex := -1;
  end;
  if (Index <> -1) then
    ListBox.ItemIndex := Index;
end;

procedure TfrmdxMemDataEditor.ListBoxStartDrag(Sender: TObject;
  var DragObject: TDragObject);
begin
  OldDragIndex := -1;
end;

procedure TfrmdxMemDataEditor.ListBoxEndDrag(Sender, Target: TObject; X,
  Y: Integer);
begin
  if OldDragIndex <> -1 then
  begin
    ListBox.Selected[OldDragIndex] := False;
    OldDragIndex := -1;
  end;
end;

procedure TfrmdxMemDataEditor.ListBoxDragDrop(Sender, Source: TObject; X,
  Y: Integer);
var
  i, Index: Integer;
  List: TList;
begin
  if OldDragIndex <> -1 then
  begin
    ListBox.Selected[OldDragIndex] := False;
    OldDragIndex := -1;
  end;
  Index := ListBox.ItemAtPos(Point(X, Y), True);
  if (Index <> -1) and (Data <> nil) then
  begin
    List := TList.Create;
    try
      GetSelection(List);
      if TField(List[0]).Index > Index then
        for i := List.Count - 1 downto 0 do
          TField(List[i]).Index := Index + 1
      else
        for i := 0 to List.Count - 1 do
          TField(List[i]).Index := Index + 1;
      if FormDesigner <> nil then
        FormDesigner.Modified;
      FillList;
      SetSelection(List);
      ListBoxClick(nil);
    finally
      List.Free;
    end;
  end;
end;

procedure TfrmdxMemDataEditor.CreateControls;

  function CreateMenuItem(ACaption: String; AShortCut: TShortCut; ANotifyEvent: TNotifyEvent): TMenuItem;
  begin
    Result := TMenuItem.Create(pmColumns);
    pmColumns.Items.Add(Result);
    Result.Caption := ACaption;
    Result.ShortCut := AShortCut;
    Result.OnClick := ANotifyEvent;
  end;

begin
  pmColumns := TPopupMenu.Create(self);
  CreateMenuItem('&Add...', 45, BAddClick);
  CreateMenuItem('&Delete', 46, BDeleteClick);
  CreateMenuItem('Move &Up', 0, miUpClick);
  CreateMenuItem('Move Dow&n', 0, miDownClick);
  CreateMenuItem('&Select All', 0, miSelectAllClick);
  CreateMenuItem('-', 0, nil);
  miShowButtons := CreateMenuItem('&Show Buttons', 0, miShowButtonsClick);
  miShowButtons.Checked := True;

  ListBox := TListBox.Create(self);
  with ListBox do
  begin
    Parent := self;
    Align := alClient;
    ListBox.DragMode := dmAutomatic;
    ItemHeight := 16;
    MultiSelect := True;
    PopupMenu := pmColumns;
    TabOrder := 0;
    OnClick := ListBoxClick;
    OnDragDrop := ListBoxDragDrop;
    OnDragOver := ListBoxDragOver;
    OnEndDrag := ListBoxEndDrag;
    OnStartDrag := ListBoxStartDrag;
  end;

  pnButtons := TPanel.Create(self);
  with pnButtons do
  begin
    Parent := self;
    Width := 107;
    Align := alRight;
    BevelOuter := bvNone;
    TabOrder := 1;
  end;

  BAdd := TButton.Create(self);
  with BAdd do
  begin
    Parent := pnButtons;
    Left := 8;
    Top := 7;
    Width := 92;
    Height := 28;
    Caption := '&Add ...';
    OnClick := BAddClick;
  end;

  BDelete := TButton.Create(self);
  with BDelete do
  begin
    Parent := pnButtons;
    Left := BAdd.Left;
    Top := BAdd.Top + BAdd.Height + BAdd.Top;
    Width := BAdd.Width;
    Height := BAdd.Height;
    Caption := '&Delete';
    OnClick := BDeleteClick;
  end;

  BUp := TButton.Create(self);
  with BUp do
  begin
    Parent := pnButtons;
    Left := BAdd.Left;
    Top := BDelete.Top + BDelete.Height + BAdd.Top;
    Width := BAdd.Width;
    Height := BAdd.Height;
    Caption := 'Move &Up';
    OnClick := miUpClick;
  end;

  BDown := TButton.Create(self);
  with BDown do
  begin
    Parent := pnButtons;
    Left := BAdd.Left;
    Top := BUp.Top + BUp.Height + BAdd.Top;
    Width := BAdd.Width;
    Height := BAdd.Height;
    Caption := 'Move Dow&n';
    OnClick := miDownClick;
  end;

  ActiveControl := ListBox;
  BorderIcons := [biSystemMenu];

    BorderStyle := bsSizeToolWin;

  Caption := 'Columns Editor';
  Left := 100;
  Top := 100;
  Color := clBtnFace;
  OnClose := FormClose;
end;

procedure TfrmdxMemDataEditor.MoveField(ADirection: Integer);
var
  i: Integer;
  List: TList;
begin
  if Data <> nil then
  begin
    List := TList.Create;
    try
      GetSelection(List);
      for i := 0 to List.Count - 1 do
        TField(List[i]).Index := TField(List[i]).Index + ADirection;
      if FormDesigner <> nil then
        FormDesigner.Modified;
      FillList;
      SetSelection(List);
    finally
      List.Free;
    end;
    ListBoxClick(nil);
  end;
end;

procedure TfrmdxMemDataEditor.GetSelection(AList: TList);
var
  I: Integer;
begin
  for I := 0 to ListBox.Items.Count - 1 do
    if ListBox.Selected[I] then
      AList.Add(ListBox.Items.Objects[i]);
end;

procedure TfrmdxMemDataEditor.SetSelection(AList: TList);
var
  I: Integer;
begin
  for I := 0 to ListBox.Items.Count - 1 do
    ListBox.Selected[I] := AList.IndexOf(ListBox.Items.Objects[I]) <> -1;
end;

{$IFDEF DELPHI9}
procedure TfrmdxMemDataEditor.CreateParams(var Params: TCreateParams);
begin
  inherited;
  Params.WndParent := Application.MainForm.Handle;
end;
{$ENDIF}

initialization
  FormList := TList.Create;

finalization
  FormList.Free;

end.

⌨️ 快捷键说明

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