拖一个LIstbox1和Edit2到界面上
procedure TForm8.ListBox1DblClick(Sender: TObject); var ItemIndex: Integer; begin ItemIndex := ListBox1.ItemIndex; // 获取双击的项 if ItemIndex >= 0 then begin // 弹出输入框 让用户输入 edit2.Text:= ListBox1.Items[ItemIndex]; edit2.SetBounds(listbox1.Left+2,listbox1.ItemHeight*(ListBox1.ItemIndex)//+ ToolBar2.Height ,listbox1.Width , listbox1.ItemHeight+2); edit2.Visible:=true; if edit2.CanFocus then edit2.Focused; end; end;
procedure TForm8.Edit2KeyPress(Sender: TObject; var Key: Char); //双击 修改表名 var aListBoxIndex: integer; begin case Key of #27: begin //ESC edit2.Visible:=false; edit2.Text:=''; exit; end; #13: if (trim(Edit2.Text) <> '') then begin //回车键 aListBoxIndex:= listbox1.ItemIndex; if listbox1.Items.IndexOf(trim(Edit2.Text)) >=0 then begin //OutResltMemo.Lines.Text:='表 '+trim(Edit2.Text) +'重复' ; Exit; end; if (leftStr(Edit2.Text,1)>='0') and (leftStr(Edit2.Text,1)<='9') then begin // OutResltMemo.Lines.Text:='表名 不能以 数字 开头' ; Exit; end; if FDConnection1.Connected then begin FDConnection1.ExecSQL(' ALTER TABLE '+ ListBox1.Items[ListBox1.ItemIndex] +' rename to ' +trim(Edit2.Text)); Edit2.Visible := false; // FDConnection1.GetTableNames('', '', '', ListBox1.Items); listbox1.ItemIndex:= aListBoxIndex; end; end; end; end;