如何将以下文本中的数据存入两维数组中。UP有分!!

weijf1979 2003-07-07 10:03:52
文本内容是:
问题一|是|否
问题二|是|否
问题三|是|否

先把文本内容读入数组。

然后在窗体上2个Lab,lab1显示当前第几行 lab2显示问题一(二,三)
两个Radiobtn. 分别显示“是”和“否”
一个Buton。点击后再次对窗体初始化。
...全文
35 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
dongliu 2003-07-07
  • 打赏
  • 举报
回复
假设文本中问题和答案之间使用空格分开的,则把刚才回答的内容改动一下
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;
yjw1018 2003-07-07
  • 打赏
  • 举报
回复
学习ing
linx88 2003-07-07
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
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.
pingshx 2003-07-07
  • 打赏
  • 举报
回复
t:Tstrings;
i:integer;
t:=tstringlist.create;
t.loadfrom('your file name');
for i:=0 to t.Count-1 do
t[i]……………………
IwantFlay 2003-07-07
  • 打赏
  • 举报
回复
up
dongliu 2003-07-07
  • 打赏
  • 举报
回复
窗体的全局变量
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;


coreblood 2003-07-07
  • 打赏
  • 举报
回复
还是没明白

你说吧想干什么?

把你操作的文本也给我们看哈撒

weijf1979 2003-07-07
  • 打赏
  • 举报
回复
再次更正:lab1应该显示文本中读的数据是第几行
weijf1979 2003-07-07
  • 打赏
  • 举报
回复
不好意思,是我描述的不清楚,我再描述一编:
有这样一个文本,它的内容是:
问题一|是|否
问题二|是|否
问题三|是|否

先把它读入一个二维数组中,然后最窗体初始化。窗体上2个Lab,lab1显示文本中当前第1行数据。
lab2显示“问题一”,两个Radiobtn. 分别显示“是”和“否”。
一个Button。点击后再次对窗体初始化。就是lab1应该显示第二行数据,lab2显示“问题二”以此类推。
tw_cshn 2003-07-07
  • 打赏
  • 举报
回复
你的意思是你要把字符转换为四则运算吧
outer2000 2003-07-07
  • 打赏
  • 举报
回复
好象是道题啊,不过没看明白;SORRY;
delphimo 2003-07-07
  • 打赏
  • 举报
回复
写一个结构体数组:结构体的内容就是:问题一|是|否
然后把他放到数组里去
ahjoe 2003-07-07
  • 打赏
  • 举报
回复
问题描述不清楚。
Means_pan 2003-07-07
  • 打赏
  • 举报
回复
路过up
weijf1979 2003-07-07
  • 打赏
  • 举报
回复
谢谢各位的指导。可是,我照着做,好像不行啊。
还有,好像大家没明白我的意思。是不是我还没表达清楚啊!!
我再说一编吧,再次感谢各位对我指导。
比如文本中:
问题一|是|否
问题二|是|否
问题三|是|否
如何读入数组Array[0..2,0..2]中。对分隔符“|”在读数据的时候如何判断。

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧