//这段代码的功能就是用特定的字符串填充指定数据表指定字段的内容
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;type
TWork = class
published
procedure SetConnect;
procedure SetStrField;
private
StrTable:string;
StrField:string;
SetStr:string;
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TWork.SetConnect;
begin
if Form1.OpenDialog1.Execute then
begin
Form1.ADOConnection1.ConnectionString:=Form1.OpenDialog1.FileName;
Form1.ADOQuery1.Connection:=Form1.ADOConnection1;
end;
StrTable:=InputBox('输入数据表名称:','','');
StrField:=InputBox('输入字段名称:','','');
SetStr:=InputBox('需要输入的字符串:','','');
end;procedure TWork.SetStrField;
begin
Form1.ADOQuery1.SQL.Clear;
Form1.ADOQuery1.SQL.Add('Update '+StrTable+' Set '+StrField+'="'+SetStr+'"');
Form1.ADOQuery1.ExecSQL;
end;procedure TForm1.Button1Click(Sender: TObject);
var
Work:TWork;
begin
Try
begin
Work:=TWork.Create;
Work.SetConnect;
Work.SetStrField;
end
finally
begin
Work.Free;
FreeAndNil(Work);
end;
end;
end;end.
//这段代码的功能就是用特定的字符串填充指定数据表指定字段的内容我搞不清楚的情况是这样:
我操作了一次以后,第二次点击Button1,就有错误提示:类已经创建,可是我不是已经Free了吗
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB;type
TForm1 = class(TForm)
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;type
TWork = class
published
procedure SetConnect;
procedure SetStrField;
private
StrTable:string;
StrField:string;
SetStr:string;
end;
var
Form1: TForm1;implementation{$R *.dfm}procedure TWork.SetConnect;
begin
if Form1.OpenDialog1.Execute then
begin
Form1.ADOConnection1.ConnectionString:=Form1.OpenDialog1.FileName;
Form1.ADOQuery1.Connection:=Form1.ADOConnection1;
end;
StrTable:=InputBox('输入数据表名称:','','');
StrField:=InputBox('输入字段名称:','','');
SetStr:=InputBox('需要输入的字符串:','','');
end;procedure TWork.SetStrField;
begin
Form1.ADOQuery1.SQL.Clear;
Form1.ADOQuery1.SQL.Add('Update '+StrTable+' Set '+StrField+'="'+SetStr+'"');
Form1.ADOQuery1.ExecSQL;
end;procedure TForm1.Button1Click(Sender: TObject);
var
Work:TWork;
begin
Try
begin
Work:=TWork.Create;
Work.SetConnect;
Work.SetStrField;
end
finally
begin
Work.Free;
FreeAndNil(Work);
end;
end;
end;end.
//这段代码的功能就是用特定的字符串填充指定数据表指定字段的内容我搞不清楚的情况是这样:
我操作了一次以后,第二次点击Button1,就有错误提示:类已经创建,可是我不是已经Free了吗
Form1.ADOConnection1.ConnectionString:=Form1.OpenDialog1.FileName;
Form1.ADOQuery1.Connection:=Form1.ADOConnection1;
这样看看行不行?