文本内容是:
问题一|是|否
问题二|是|否
问题三|是|否先把文本内容读入数组。然后在窗体上2个Lab,lab1显示当前第几行 lab2显示问题一(二,三)
两个Radiobtn. 分别显示“是”和“否”
一个Buton。点击后再次对窗体初始化。
问题一|是|否
问题二|是|否
问题三|是|否先把文本内容读入数组。然后在窗体上2个Lab,lab1显示当前第几行 lab2显示问题一(二,三)
两个Radiobtn. 分别显示“是”和“否”
一个Buton。点击后再次对窗体初始化。
解决方案 »
- 怎么让文本框只输入数字呢?
- delphi 开发串口通讯程序问题
- 關於nmsmtp1發郵件得問題,我現在可以發正文,但是我卻不知道怎麼發附件,可以用該控件發附件嗎?
- 高手帮忙我一下 delphi 中去掉字符串前后空格的函数是?
- 如何用winexec或者shellexecute调用拨号连接(操作系统是Win2000)!
- 急急急 数据库方面的 是怎么回事情 100分全给
- 求助
- 如何计算时间的问题
- 窗体的创建问题
- 小白求问 才开始学 搞不懂啊 拜求各位大佬
- 导入到EXCEL中的数据,怎么无法用来求和!?
- 请问:总提示rtl60.bpl(报表连接库)找不到,Qreport面版中的第一个控件加载不到窗体中?????
有这样一个文本,它的内容是:
问题一|是|否
问题二|是|否
问题三|是|否先把它读入一个二维数组中,然后最窗体初始化。窗体上2个Lab,lab1显示文本中当前第1行数据。
lab2显示“问题一”,两个Radiobtn. 分别显示“是”和“否”。
一个Button。点击后再次对窗体初始化。就是lab1应该显示第二行数据,lab2显示“问题二”以此类推。
type
component = record
question:string;
answer1:string;
answer2:string;
end;
var
Form1: TForm1;
line:integer;
array_question:array of component;procedure TForm1.FormCreate(Sender: TObject);
var
txt:textfile;
num:integer;
i:integer;
temp:string;
mystrings:TStrings;
begin
if not FileExists('c:\1.txt') then
begin
showmessage('文本文件不存在!');
exit;
end ;
AssignFile(txt,'c:\1.txt');
Reset(txt);
mystrings:= TStringList.Create;
mystrings.loadfromfile('c:\1.txt');
num:=mystrings.count;setlength(array_question,num+1);
if num=0 then
begin
showmessage('没有试题!');
exit
end
else
begin
for i:=1 to num do
begin
read(txt,array_question[i].question);
read(txt,array_question[i].answer1);
read(txt,array_question[i].answer2);
end;
line:=1;
Label1.Caption:='第'+inttostr(line)+'行';
Label2.Caption:=array_question[line].question;
RadioButton1.Caption:=array_question[line].answer1;
RadioButton2.Caption:=array_question[line].answer2;
end;end;procedure TForm1.Button2Click(Sender: TObject); 提交按钮
begin
if line<high(array_question) then
begin
line:=line+1;
Label1.Caption:='第'+inttostr(line)+'行';
Label2.Caption:=array_question[line].question;
RadioButton1.Caption:=array_question[line].answer1;
RadioButton2.Caption:=array_question[line].answer2;
end
else
begin
showmessage('已经是最后一道题了');
end;
end;
i:integer;
t:=tstringlist.create;
t.loadfrom('your file name');
for i:=0 to t.Count-1 do
t[i]……………………
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;type
TForm1 = class(TForm)
ListBox1: TListBox;
Button1: TButton;
Label1: TLabel;
Label2: TLabel;
RadioGroup1: TRadioGroup;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
procedure ListBox1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
begin
IF Opendialog1.Execute then
listbox1.Items.LoadFromFile(opendialog1.FileName);
end;procedure TForm1.ListBox1Click(Sender: TObject);
var
s,s1,s2,s3:string;
begin
// radiogroup1 0:是,1:否
s:=listbox1.Items.Strings[listbox1.itemindex];
s1:=copy(s,1,pos('|',s)-1);
s:=copy(s,pos('|',s)+1,length(s)-pos('|',s));
s2:=copy(s,1,pos('|',s)-1);
s:=copy(s,pos('|',s)+1,length(s)-pos('|',s));
s3:=s;
label1.Caption:=inttostr(listbox1.ItemIndex);
label2.Caption:=s1;
if s2='是' then
radiogroup1.ItemIndex:=0
else if s3='是' then
radiogroup1.ItemIndex:=1
else radiogroup1.ItemIndex:=-1;end;end.
for i:=1 to num do
begin
read(txt,array_question[i].question);
read(txt,array_question[i].answer1);
read(txt,array_question[i].answer2);
end;
改为
for i:=1 to num do
begin
read(txt,temp);
array_question[i].question:=copy(temp,1,pos(' ',temp));
temp:=stringreplace(temp,array_question[i].question,'',[]);
array_question[i].answer1:=copy(temp,1,pos(' ',temp));
temp:=stringreplace(temp,array_question[i].answer1,'',[]);
array_question[i].answer2:=temp;
readln(txt);
end;
还有,好像大家没明白我的意思。是不是我还没表达清楚啊!!
我再说一编吧,再次感谢各位对我指导。
比如文本中:
问题一|是|否
问题二|是|否
问题三|是|否
如何读入数组Array[0..2,0..2]中。对分隔符“|”在读数据的时候如何判断。