J
js916
Unregistered / Unconfirmed
GUEST, unregistred user!
我想做一个模拟考试系统,我的代码如下:
问题1.我的题目是由dbmemo1和一张图片组成,现在是我点击dbnavigator1的aferscroll后,只有dbmemo1中的题可以变化,图片总是显示第一题的,咋回事那?
问题2.再有那个num的数好像总是没有变化,不懂,蒙了
请大侠帮我看看吧
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Menus, DB, ADODB, StdCtrls, DBCtrls, ExtCtrls;
type
TForm3 = class(TForm)
MainMenu1: TMainMenu;
start: TMenuItem;
dzja: TMenuItem;
mssp: TMenuItem;
mnkc: TMenuItem;
out: TMenuItem;
StatusBar1: TStatusBar;
start1: TMenuItem;
daja1: TMenuItem;
mssp1: TMenuItem;
out1: TMenuItem;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
DBMemo1: TDBMemo;
DataSource1: TDataSource;
DBText1: TDBText;
mnkc1: TMenuItem;
mnkc2: TMenuItem;
ComboBox1: TComboBox;
Button1: TButton;
DBNavigator1: TDBNavigator;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
procedure start1Click(Sender: TObject);
procedure mssp1Click(Sender: TObject);
procedure daja1Click(Sender: TObject);
procedure out1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ADOQuery1AfterScroll(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
//设置用户自定义类
type student=Record
TestPaper:string;
Score:integer;
end;
type answer=Record
standard:string;
ecaminee:string;
result:integer;
path:string;
end;
var
Form3: TForm3;
implementation
uses main, Unit2, Unit1;
//全局变量
var
stu:student;
examcount:integer;
ans:array of answer;
{$R *.dfm}
procedure TForm3.start1Click(Sender: TObject);
begin
form3.hide;
mainform.show;
end;
procedure TForm3.mssp1Click(Sender: TObject);
begin
form3.hide;
form2.show;
end;
procedure TForm3.daja1Click(Sender: TObject);
begin
form3.hide;
form1.show;
end;
procedure TForm3.out1Click(Sender: TObject);
begin
mainform.close;
end;
procedure TForm3.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.ItemIndex=0 then
begin
stu.TestPaper:='模拟题1';
button1.Caption:='模拟题1';
end;
if ComboBox1.ItemIndex=1 then
begin
stu.TestPaper:='模拟题2';
button1.Caption:='模拟题2';
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
allpath:string;
num:integer;
begin
//取题
with ADOQuery1 do
begin
close;
sql.clear;
sql.Add('select * from '+stu.TestPaper+' order by 题号');
open;
DBMemo1.DataSource:=DataSource1;
DBText1.DataSource:=DataSource1;
DBText1.DataField:='题号';
DBMemo1.DataField:='题目';
examCount:=RecordCount;
SetLength(ans,examCount+1);
num:=ADOQuery1.FieldByName('题号').value;
label1.caption:=inttostr(num);
ans[num].path:=ADOQuery1.FieldByName('路径').Value;
allpath:=ExtractFilePath(Application.ExeName)+ans[num].path;
Image1.Picture.LoadFromFile(allpath);
end;
end;
procedure TForm3.ADOQuery1AfterScroll(DataSet: TDataSet);
var
allpath1:string;
num1:integer;
begin
with ADOQuery1 do
begin
num1:=ADOQuery1.FieldByName('题号').value;
label1.caption:=inttostr(num1);
ans[num1].path:=ADOQuery1.FieldByName('路径').Value;
allpath1:=ExtractFilePath(Application.ExeName)+ans[num1].path;
Image1.Picture.LoadFromFile(allpath1);
end;
end;
end.
问题1.我的题目是由dbmemo1和一张图片组成,现在是我点击dbnavigator1的aferscroll后,只有dbmemo1中的题可以变化,图片总是显示第一题的,咋回事那?
问题2.再有那个num的数好像总是没有变化,不懂,蒙了
请大侠帮我看看吧
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, Menus, DB, ADODB, StdCtrls, DBCtrls, ExtCtrls;
type
TForm3 = class(TForm)
MainMenu1: TMainMenu;
start: TMenuItem;
dzja: TMenuItem;
mssp: TMenuItem;
mnkc: TMenuItem;
out: TMenuItem;
StatusBar1: TStatusBar;
start1: TMenuItem;
daja1: TMenuItem;
mssp1: TMenuItem;
out1: TMenuItem;
ADOConnection1: TADOConnection;
ADOQuery1: TADOQuery;
ADOQuery2: TADOQuery;
DBMemo1: TDBMemo;
DataSource1: TDataSource;
DBText1: TDBText;
mnkc1: TMenuItem;
mnkc2: TMenuItem;
ComboBox1: TComboBox;
Button1: TButton;
DBNavigator1: TDBNavigator;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
procedure start1Click(Sender: TObject);
procedure mssp1Click(Sender: TObject);
procedure daja1Click(Sender: TObject);
procedure out1Click(Sender: TObject);
procedure ComboBox1Change(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure ADOQuery1AfterScroll(DataSet: TDataSet);
private
{ Private declarations }
public
{ Public declarations }
end;
//设置用户自定义类
type student=Record
TestPaper:string;
Score:integer;
end;
type answer=Record
standard:string;
ecaminee:string;
result:integer;
path:string;
end;
var
Form3: TForm3;
implementation
uses main, Unit2, Unit1;
//全局变量
var
stu:student;
examcount:integer;
ans:array of answer;
{$R *.dfm}
procedure TForm3.start1Click(Sender: TObject);
begin
form3.hide;
mainform.show;
end;
procedure TForm3.mssp1Click(Sender: TObject);
begin
form3.hide;
form2.show;
end;
procedure TForm3.daja1Click(Sender: TObject);
begin
form3.hide;
form1.show;
end;
procedure TForm3.out1Click(Sender: TObject);
begin
mainform.close;
end;
procedure TForm3.ComboBox1Change(Sender: TObject);
begin
if ComboBox1.ItemIndex=0 then
begin
stu.TestPaper:='模拟题1';
button1.Caption:='模拟题1';
end;
if ComboBox1.ItemIndex=1 then
begin
stu.TestPaper:='模拟题2';
button1.Caption:='模拟题2';
end;
end;
procedure TForm3.Button1Click(Sender: TObject);
var
allpath:string;
num:integer;
begin
//取题
with ADOQuery1 do
begin
close;
sql.clear;
sql.Add('select * from '+stu.TestPaper+' order by 题号');
open;
DBMemo1.DataSource:=DataSource1;
DBText1.DataSource:=DataSource1;
DBText1.DataField:='题号';
DBMemo1.DataField:='题目';
examCount:=RecordCount;
SetLength(ans,examCount+1);
num:=ADOQuery1.FieldByName('题号').value;
label1.caption:=inttostr(num);
ans[num].path:=ADOQuery1.FieldByName('路径').Value;
allpath:=ExtractFilePath(Application.ExeName)+ans[num].path;
Image1.Picture.LoadFromFile(allpath);
end;
end;
procedure TForm3.ADOQuery1AfterScroll(DataSet: TDataSet);
var
allpath1:string;
num1:integer;
begin
with ADOQuery1 do
begin
num1:=ADOQuery1.FieldByName('题号').value;
label1.caption:=inttostr(num1);
ans[num1].path:=ADOQuery1.FieldByName('路径').Value;
allpath1:=ExtractFilePath(Application.ExeName)+ans[num1].path;
Image1.Picture.LoadFromFile(allpath1);
end;
end;
end.