文本内容是:
问题一|是|否
问题二|是|否
问题三|是|否先把文本内容读入数组。然后在窗体上2个Lab,lab1显示当前第几行 lab2显示问题一(二,三)
两个Radiobtn. 分别显示“是”和“否”
一个Buton。点击后再次对窗体初始化。

解决方案 »

  1.   

    好象是道题啊,不过没看明白;SORRY;
      

  2.   

    不好意思,是我描述的不清楚,我再描述一编:
    有这样一个文本,它的内容是:
    问题一|是|否
    问题二|是|否
    问题三|是|否先把它读入一个二维数组中,然后最窗体初始化。窗体上2个Lab,lab1显示文本中当前第1行数据。
    lab2显示“问题一”,两个Radiobtn. 分别显示“是”和“否”。
    一个Button。点击后再次对窗体初始化。就是lab1应该显示第二行数据,lab2显示“问题二”以此类推。
      

  3.   

    再次更正:lab1应该显示文本中读的数据是第几行
      

  4.   

    窗体的全局变量
    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;
      

  5.   

    t:Tstrings;
    i:integer;
    t:=tstringlist.create;
    t.loadfrom('your file name');
    for i:=0 to t.Count-1 do
       t[i]……………………
      

  6.   

    unit Unit1;interfaceuses
      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.
      

  7.   

    假设文本中问题和答案之间使用空格分开的,则把刚才回答的内容改动一下
    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;
      

  8.   

    谢谢各位的指导。可是,我照着做,好像不行啊。
    还有,好像大家没明白我的意思。是不是我还没表达清楚啊!!
    我再说一编吧,再次感谢各位对我指导。
    比如文本中:
    问题一|是|否
    问题二|是|否
    问题三|是|否
    如何读入数组Array[0..2,0..2]中。对分隔符“|”在读数据的时候如何判断。