这是我的程序的源代码,但是在运行的时候出了问题,怎么办?请帮忙看看!!!!(40分)

  • 主题发起人 主题发起人 luckyon
  • 开始时间 开始时间
L

luckyon

Unregistered / Unconfirmed
GUEST, unregistred user!
这是我的程序的源代码
但是在运行的时候出了问题
怎么办?请帮忙看看!!!!
program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

{$R *.RES}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.
-------------------------------------------------------
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Grids, DBGrids, Db, ADODB, ExtCtrls;

type
TForm1 = class(TForm)
RadioGroup1: TRadioGroup;
ADOConnection1: TADOConnection;
ADOTable1: TADOTable;
DataSource1: TDataSource;
DBGrid1: TDBGrid;
Button1: TButton;
Button2: TButton;
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button2Click(Sender: TObject);
begin
Close;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
RadioGroup1.ItemIndex:=0;
ADOTable1.Active:=false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
if RadioGroup1.ItemIndex=0 then

adotable1.tablename:='nan_two';
adotable1.open;
adotable1.Active:=true;

if RadioGroup1.ItemIndex=1 then
adotable1.close;
adotable1.tablename:='nv_one';
adotable1.open;
adotable1.Active:=true;

end;

end.
程序运行的时候出现了以下的错误,怎么回事?
错误:
Project Project1.exe raised exception class EDatabaseError with
message 'ADOTable1:cannot perform this operation on an open dataset',
process stopped.Use Step or Run to continue.
 
adotable1.open;
adotable1.Active:=true;
有问题,去掉其中的一个试试看[:)]
 
我试验了,但是
去掉了的话
我点第一个选项的时候可以正常显示
但是当我点击第二个选项想显示另一个表的时候
又出现了这个错误
 
改为:
procedure TForm1.Button1Click(Sender: TObject);
begin
adotable1.close;
if RadioGroup1.ItemIndex=0 then
adotable1.tablename:='nan_two';
if RadioGroup1.ItemIndex=1 then
adotable1.tablename:='nv_one';
adotable1.Active:=true;
end;
 
:)逻辑错误
 
成功
谢谢
 
多人接受答案了。
 

Similar threads

后退
顶部