?? u_litest.~pas
字號:
unit U_litest;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, StdCtrls;
type
TForm1 = class(TForm)
ListBox1: TListBox;
ListBox2: TListBox;
Button1: TButton;
Button2: TButton;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Label1: TLabel;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
try
adoquery1.SQL.Clear ;
adoquery1.Close;
adoquery1.SQL.Add('select * from na1 order by na1');
adoquery1.Open;
listbox2.Clear;
while not adoquery1.Eof do
begin
listbox2.Items.Add(adoquery1.FieldValues['na1']);
adoquery1.Next;
end;
finally
adoquery1.Close;
end;
try
adoquery1.SQL.Clear ;
adoquery1.Close;
adoquery1.SQL.Add('select * from na2 order by na2');
adoquery1.Open;
listbox1.Clear;
while not adoquery1.Eof do
begin
listbox1.Items.Add(adoquery1.FieldValues['na2']);
adoquery1.Next;
end;
finally
adoquery1.Close;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
strkc,strsql:string;
i:integer;
begin
if listbox2.ItemIndex =-1 then
begin
showmessage('請先選定要添加的記錄');
listbox2.SetFocus;
exit;
end;
strkc:=listbox2.Items[listbox2.ItemIndex] ;
for i:=0 to listbox1.Items.Count -1 do
begin
if strkc=listbox1.Items[i] then
begin
showmessage('已有此記錄');
exit;
end;
end;
strsql:='insert into na2(na2) values('''+strkc+''')';
try
adoquery1.SQL.Clear ;
adoquery1.Close;
adoquery1.SQL.Add(strsql);
adoquery1.ExecSQL;
listbox1.Items.Add(strkc) ;
except
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var
strkc,strsql:string;
begin
if listbox1.ItemIndex =-1 then
begin
showmessage('請先選定要移除的記錄');
listbox1.SetFocus;
exit;
end;
strkc:=listbox1.Items[listbox1.ItemIndex] ;
strsql:='delete from na2 where na2='''+strkc+''' ';
try
adoquery1.SQL.Clear ;
adoquery1.Close;
adoquery1.SQL.Add(strsql);
adoquery1.ExecSQL;
listbox1.Items.Delete(listbox1.ItemIndex);
except
end;
end;
end.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -