C
cnpowercn
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids, ComCtrls, Menus,
ExtCtrls, DBCtrls, Mask;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
ComboBox1: TComboBox;
Edit5: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
OpenDialog1: TOpenDialog;
ComboBox2: TComboBox;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
Edit16: TEdit;
Edit17: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label20: TLabel;
Edit18: TEdit;
Edit19: TEdit;
Edit20: TEdit;
Edit21: TEdit;
Label21: TLabel;
N4: TMenuItem;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
DBEdit7: TDBEdit;
DBEdit8: TDBEdit;
DBEdit9: TDBEdit;
DBEdit10: TDBEdit;
DBEdit11: TDBEdit;
DBEdit12: TDBEdit;
DBEdit13: TDBEdit;
DBEdit14: TDBEdit;
DBEdit15: TDBEdit;
DBEdit16: TDBEdit;
DBText1: TDBText;
DBText2: TDBText;
DBText3: TDBText;
DBText4: TDBText;
DBText5: TDBText;
DBText6: TDBText;
DBText7: TDBText;
DBText8: TDBText;
DBText9: TDBText;
DBText10: TDBText;
DBText11: TDBText;
DBText12: TDBText;
DBText13: TDBText;
DBText14: TDBText;
DBText15: TDBText;
DBText16: TDBText;
DBNavigator1: TDBNavigator;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
bm:tbookmark;
findfield:string;
implementation
{$R *.dfm}
type llabel=array[0..15] of tlabel;
text=array[0..15] of tedit;
dbtext=array[0..15] of tdbtext;
dbedit=array[0..15] of tdbedit;
var lab:llabel;
ed:text;
dbt:dbtext;
dbe:dbedit;
procedure TForm1.Button1Click(Sender: TObject);
begin
table1.First;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
table1.Prior;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
table1.Next;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
table1.Last;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
table1.Append;
end;
procedure TForm1.Button6Click(Sender: TObject);
var del:integer;
begin
del:=application.messagebox('你真的要删除吗?','Powersoft',mb_yesno);
if del=idyes then
table1.Delete;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
//if edit1.text<>'' then
//table1.InsertRecord([edit1.text,edit2.text,edit3.text,edit4.text])
//else
table1.Insert;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
table1.Edit;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
table1.Post;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
table1.Cancel;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
bm:=table1.GetBookmark;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
table1.GotoBookmark(bm);
table1.FreeBookmark(bm);
end;
procedure TForm1.Button13Click(Sender: TObject);
var k:integer;
begin
case combobox1.ItemIndex of
0:findfield:=table1.Fields[0].FieldName;
1:findfield:=table1.Fields[1].FieldName;
2:findfield:=table1.Fields[2].FieldName;
3:findfield:=table1.Fields[3].FieldName;
end;
if table1.Locate(findfield,edit5.text,[locaseinsensitive]) then
for k:=0 to table1.FieldCount-1 do
ed[k].Text:=table1.FieldValues[table1.Fields[k].FieldName]
else
showmessage('没有此记录!');
end;
procedure TForm1.N2Click(Sender: TObject);
var i:integer;
p:integer;
begin
if opendialog1.Execute then
begin
table1.DatabaseName:=opendialog1.InitialDir ;
table1.TableName:=opendialog1.FileName;
combobox2.Items.Add(table1.TableName);
table1.Active:=true;
n2.Enabled:=false;
n3.Enabled:=true;
if table1.FieldCount <17 then
begin
for i:=0 to table1.FieldCount-1 do
begin
combobox1.Items.Add(table1.Fields.FieldName);
lab.Caption :=table1.Fields.FieldName;
dbt.Caption :=table1.Fields.FieldName;
dbe.DataField :=table1.Fields.FieldName ;
end;
for p:=0 to 15 do
begin
if lab[p].Caption <>'' then
begin
lab[p].show;
ed[p].Show;
dbe[p].Show;
dbt[p].Show;
end;
end;
combobox1.ItemIndex := 0;
end
else if table1.FieldCount = 0 then
showmessage('请你打开一个表!')
else
showmessage('你打开的表字段超过16个,本软件处理不了,抱歉!')
end;
end;
procedure TForm1.N3Click(Sender: TObject);
var j:integer;
begin
n3.Enabled :=false;
n2.Enabled :=true;
for j:=0 to table1.FieldCount-1 do
begin
lab[j].Caption :='';
combobox1.Items.Delete(0);
ed[j].Text:='';
ed[j].Hide;
dbt[j].Caption :='';
dbe[j].DataField :='';
dbe[j].Hide;
end;
table1.active:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
var l:integer;
begin
lab[0]:=label5;
lab[1]:=label6;
lab[2]:=label7;
lab[3]:=label8;
lab[4]:=label9;
lab[5]:=label10;
lab[6]:=label11;
lab[7]:=label12;
lab[8]:=label13;
lab[9]:=label14;
lab[10]:=label15;
lab[11]:=label16;
lab[12]:=label17;
lab[13]:=label18;
lab[14]:=label19;
lab[15]:=label20;
ed[0]:=edit6;
ed[1]:=edit7;
ed[2]:=edit8;
ed[3]:=edit9;
ed[4]:=edit10;
ed[5]:=edit11;
ed[6]:=edit12;
ed[7]:=edit13;
ed[8]:=edit14;
ed[9]:=edit15;
ed[10]:=edit16;
ed[11]:=edit17;
ed[12]:=edit18;
ed[13]:=edit19;
ed[14]:=edit20;
ed[15]:=edit21;
dbt[0]:=dbtext1;
dbt[1]:=dbtext2;
dbt[2]:=dbtext3;
dbt[3]:=dbtext4;
dbt[4]:=dbtext5;
dbt[5]:=dbtext6;
dbt[6]:=dbtext7;
dbt[7]:=dbtext8;
dbt[8]:=dbtext9;
dbt[9]:=dbtext10;
dbt[10]:=dbtext11;
dbt[11]:=dbtext12;
dbt[12]:=dbtext13;
dbt[13]:=dbtext14;
dbt[14]:=dbtext15;
dbt[15]:=dbtext16;
dbe[0]:=dbedit1;
dbe[1]:=dbedit2;
dbe[2]:=dbedit3;
dbe[3]:=dbedit4;
dbe[4]:=dbedit5;
dbe[5]:=dbedit6;
dbe[6]:=dbedit7;
dbe[7]:=dbedit8;
dbe[8]:=dbedit9;
dbe[9]:=dbedit10;
dbe[10]:=dbedit11;
dbe[11]:=dbedit12;
dbe[12]:=dbedit13;
dbe[13]:=dbedit14;
dbe[14]:=dbedit15;
dbe[15]:=dbedit16;
for l:=0 to 15 do
begin
lab[l].Hide;
ed[l].Hide;
dbt[l].Hide;
dbe[l].Hide;
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
var i:integer;
var j:integer;
var q:integer;
begin
for j:=0 to table1.FieldCount -1 do
begin
combobox1.Items.Delete(0);
lab[j].Caption :='';
ed[j].Hide;
dbt[j].Caption :='';
dbe[j].Hide;
end;
table1.Active :=false;
table1.TableName :=combobox2.Text;
table1.Active :=true;
for i:=0 to table1.FieldCount-1 do
begin
combobox1.Items.Add(table1.Fields.FieldName);
lab.Caption :=table1.Fields.FieldName;
end;
for q:=0 to 15 do
begin
if lab[q].Caption <>'' then
begin
lab[q].show;
ed[q].Show;
dbt[q].Show;
dbe[q].Show;
end;
end;
combobox1.ItemIndex :=0;
end;
procedure TForm1.N4Click(Sender: TObject);
var button:integer;
begin
button:=Application.MessageBox('你真的要退出吗?','powersoft',Mb_YesNo);
if button = Idyes then
begin
close;
table1.Active :=false;
end;
end;
end.
问题:
1、以上程序在table1里移动指针时,dbtext为什么会消失?
2、指定查询时如果有多个字段值相同,要怎么把记录一个一个查找出来?
3、为什么在运行时会说tbookmark是unsaft type?
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids, ComCtrls, Menus,
ExtCtrls, DBCtrls, Mask;
type
TForm1 = class(TForm)
DBGrid1: TDBGrid;
DataSource1: TDataSource;
Table1: TTable;
Button1: TButton;
Button2: TButton;
Button3: TButton;
Button4: TButton;
Button5: TButton;
Button6: TButton;
Button7: TButton;
Button8: TButton;
Button9: TButton;
Button10: TButton;
Button11: TButton;
Button12: TButton;
Button13: TButton;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
ComboBox1: TComboBox;
Edit5: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Edit6: TEdit;
Edit7: TEdit;
Edit8: TEdit;
Edit9: TEdit;
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
OpenDialog1: TOpenDialog;
ComboBox2: TComboBox;
Edit10: TEdit;
Edit11: TEdit;
Edit12: TEdit;
Edit13: TEdit;
Edit14: TEdit;
Edit15: TEdit;
Edit16: TEdit;
Edit17: TEdit;
Label9: TLabel;
Label10: TLabel;
Label11: TLabel;
Label12: TLabel;
Label13: TLabel;
Label14: TLabel;
Label15: TLabel;
Label16: TLabel;
Label17: TLabel;
Label18: TLabel;
Label19: TLabel;
Label20: TLabel;
Edit18: TEdit;
Edit19: TEdit;
Edit20: TEdit;
Edit21: TEdit;
Label21: TLabel;
N4: TMenuItem;
DBEdit1: TDBEdit;
DBEdit2: TDBEdit;
DBEdit3: TDBEdit;
DBEdit4: TDBEdit;
DBEdit5: TDBEdit;
DBEdit6: TDBEdit;
DBEdit7: TDBEdit;
DBEdit8: TDBEdit;
DBEdit9: TDBEdit;
DBEdit10: TDBEdit;
DBEdit11: TDBEdit;
DBEdit12: TDBEdit;
DBEdit13: TDBEdit;
DBEdit14: TDBEdit;
DBEdit15: TDBEdit;
DBEdit16: TDBEdit;
DBText1: TDBText;
DBText2: TDBText;
DBText3: TDBText;
DBText4: TDBText;
DBText5: TDBText;
DBText6: TDBText;
DBText7: TDBText;
DBText8: TDBText;
DBText9: TDBText;
DBText10: TDBText;
DBText11: TDBText;
DBText12: TDBText;
DBText13: TDBText;
DBText14: TDBText;
DBText15: TDBText;
DBText16: TDBText;
DBNavigator1: TDBNavigator;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
procedure Button7Click(Sender: TObject);
procedure Button8Click(Sender: TObject);
procedure Button9Click(Sender: TObject);
procedure Button10Click(Sender: TObject);
procedure Button11Click(Sender: TObject);
procedure Button12Click(Sender: TObject);
procedure Button13Click(Sender: TObject);
procedure N2Click(Sender: TObject);
procedure N3Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ComboBox2Change(Sender: TObject);
procedure N4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
bm:tbookmark;
findfield:string;
implementation
{$R *.dfm}
type llabel=array[0..15] of tlabel;
text=array[0..15] of tedit;
dbtext=array[0..15] of tdbtext;
dbedit=array[0..15] of tdbedit;
var lab:llabel;
ed:text;
dbt:dbtext;
dbe:dbedit;
procedure TForm1.Button1Click(Sender: TObject);
begin
table1.First;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
table1.Prior;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
table1.Next;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
table1.Last;
end;
procedure TForm1.Button5Click(Sender: TObject);
begin
table1.Append;
end;
procedure TForm1.Button6Click(Sender: TObject);
var del:integer;
begin
del:=application.messagebox('你真的要删除吗?','Powersoft',mb_yesno);
if del=idyes then
table1.Delete;
end;
procedure TForm1.Button7Click(Sender: TObject);
begin
//if edit1.text<>'' then
//table1.InsertRecord([edit1.text,edit2.text,edit3.text,edit4.text])
//else
table1.Insert;
end;
procedure TForm1.Button8Click(Sender: TObject);
begin
table1.Edit;
end;
procedure TForm1.Button9Click(Sender: TObject);
begin
table1.Post;
end;
procedure TForm1.Button10Click(Sender: TObject);
begin
table1.Cancel;
end;
procedure TForm1.Button11Click(Sender: TObject);
begin
bm:=table1.GetBookmark;
end;
procedure TForm1.Button12Click(Sender: TObject);
begin
table1.GotoBookmark(bm);
table1.FreeBookmark(bm);
end;
procedure TForm1.Button13Click(Sender: TObject);
var k:integer;
begin
case combobox1.ItemIndex of
0:findfield:=table1.Fields[0].FieldName;
1:findfield:=table1.Fields[1].FieldName;
2:findfield:=table1.Fields[2].FieldName;
3:findfield:=table1.Fields[3].FieldName;
end;
if table1.Locate(findfield,edit5.text,[locaseinsensitive]) then
for k:=0 to table1.FieldCount-1 do
ed[k].Text:=table1.FieldValues[table1.Fields[k].FieldName]
else
showmessage('没有此记录!');
end;
procedure TForm1.N2Click(Sender: TObject);
var i:integer;
p:integer;
begin
if opendialog1.Execute then
begin
table1.DatabaseName:=opendialog1.InitialDir ;
table1.TableName:=opendialog1.FileName;
combobox2.Items.Add(table1.TableName);
table1.Active:=true;
n2.Enabled:=false;
n3.Enabled:=true;
if table1.FieldCount <17 then
begin
for i:=0 to table1.FieldCount-1 do
begin
combobox1.Items.Add(table1.Fields.FieldName);
lab.Caption :=table1.Fields.FieldName;
dbt.Caption :=table1.Fields.FieldName;
dbe.DataField :=table1.Fields.FieldName ;
end;
for p:=0 to 15 do
begin
if lab[p].Caption <>'' then
begin
lab[p].show;
ed[p].Show;
dbe[p].Show;
dbt[p].Show;
end;
end;
combobox1.ItemIndex := 0;
end
else if table1.FieldCount = 0 then
showmessage('请你打开一个表!')
else
showmessage('你打开的表字段超过16个,本软件处理不了,抱歉!')
end;
end;
procedure TForm1.N3Click(Sender: TObject);
var j:integer;
begin
n3.Enabled :=false;
n2.Enabled :=true;
for j:=0 to table1.FieldCount-1 do
begin
lab[j].Caption :='';
combobox1.Items.Delete(0);
ed[j].Text:='';
ed[j].Hide;
dbt[j].Caption :='';
dbe[j].DataField :='';
dbe[j].Hide;
end;
table1.active:=false;
end;
procedure TForm1.FormCreate(Sender: TObject);
var l:integer;
begin
lab[0]:=label5;
lab[1]:=label6;
lab[2]:=label7;
lab[3]:=label8;
lab[4]:=label9;
lab[5]:=label10;
lab[6]:=label11;
lab[7]:=label12;
lab[8]:=label13;
lab[9]:=label14;
lab[10]:=label15;
lab[11]:=label16;
lab[12]:=label17;
lab[13]:=label18;
lab[14]:=label19;
lab[15]:=label20;
ed[0]:=edit6;
ed[1]:=edit7;
ed[2]:=edit8;
ed[3]:=edit9;
ed[4]:=edit10;
ed[5]:=edit11;
ed[6]:=edit12;
ed[7]:=edit13;
ed[8]:=edit14;
ed[9]:=edit15;
ed[10]:=edit16;
ed[11]:=edit17;
ed[12]:=edit18;
ed[13]:=edit19;
ed[14]:=edit20;
ed[15]:=edit21;
dbt[0]:=dbtext1;
dbt[1]:=dbtext2;
dbt[2]:=dbtext3;
dbt[3]:=dbtext4;
dbt[4]:=dbtext5;
dbt[5]:=dbtext6;
dbt[6]:=dbtext7;
dbt[7]:=dbtext8;
dbt[8]:=dbtext9;
dbt[9]:=dbtext10;
dbt[10]:=dbtext11;
dbt[11]:=dbtext12;
dbt[12]:=dbtext13;
dbt[13]:=dbtext14;
dbt[14]:=dbtext15;
dbt[15]:=dbtext16;
dbe[0]:=dbedit1;
dbe[1]:=dbedit2;
dbe[2]:=dbedit3;
dbe[3]:=dbedit4;
dbe[4]:=dbedit5;
dbe[5]:=dbedit6;
dbe[6]:=dbedit7;
dbe[7]:=dbedit8;
dbe[8]:=dbedit9;
dbe[9]:=dbedit10;
dbe[10]:=dbedit11;
dbe[11]:=dbedit12;
dbe[12]:=dbedit13;
dbe[13]:=dbedit14;
dbe[14]:=dbedit15;
dbe[15]:=dbedit16;
for l:=0 to 15 do
begin
lab[l].Hide;
ed[l].Hide;
dbt[l].Hide;
dbe[l].Hide;
end;
end;
procedure TForm1.ComboBox2Change(Sender: TObject);
var i:integer;
var j:integer;
var q:integer;
begin
for j:=0 to table1.FieldCount -1 do
begin
combobox1.Items.Delete(0);
lab[j].Caption :='';
ed[j].Hide;
dbt[j].Caption :='';
dbe[j].Hide;
end;
table1.Active :=false;
table1.TableName :=combobox2.Text;
table1.Active :=true;
for i:=0 to table1.FieldCount-1 do
begin
combobox1.Items.Add(table1.Fields.FieldName);
lab.Caption :=table1.Fields.FieldName;
end;
for q:=0 to 15 do
begin
if lab[q].Caption <>'' then
begin
lab[q].show;
ed[q].Show;
dbt[q].Show;
dbe[q].Show;
end;
end;
combobox1.ItemIndex :=0;
end;
procedure TForm1.N4Click(Sender: TObject);
var button:integer;
begin
button:=Application.MessageBox('你真的要退出吗?','powersoft',Mb_YesNo);
if button = Idyes then
begin
close;
table1.Active :=false;
end;
end;
end.
问题:
1、以上程序在table1里移动指针时,dbtext为什么会消失?
2、指定查询时如果有多个字段值相同,要怎么把记录一个一个查找出来?
3、为什么在运行时会说tbookmark是unsaft type?