Здраствуйте! Нужно подобие анкеты.Создаешь динамически компоненты,Label'ы заполняются из текстового документа Task и ответы идут в текстовый документ Otvet. На кнопку пишется программа,которая сохраняет ответы в текстовый документ. Происходит ошибка Не могли бы вы проверить ,что не так.
Код | unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) NewLabel1: TLabel; NewEdit1: TEdit; NewComboBox1: TComboBox; Button1: TButton; NewLabel2: TLabel; NewEdit2: TEdit; NewLabel3: TLabel; NewLabel4: TLabel; NewEdit3: TEdit; procedure FormCreate(Sender: TObject); procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; i:integer; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var FileName:string; f:TextFile; buf,buf1,buf2,buf3,buf4:String; i:Integer; begin FileName:='Task.txt'; AssignFile(f,FileName); reset(f); begin i:=1; while not eof(f) do begin readln(f,buf); readln(f,buf1); readln(f,buf2); readln(f,buf3); readln(f,buf4); begin NewLabel1:=Tlabel.Create(self); NewLabel1.parent:=self; NewLabel1.Left:=100; NewLabel1.top:=50; NewLabel1.caption:=buf; NewEdit1:=tedit.create(self); NewEdit1.parent:=self; NewEdit1.left:=300; NewEdit1.top:=50; NewLabel2:=Tlabel.Create(self); NewLabel2.parent:=self; NewLabel2.Left:=100; NewLabel2.top:=70; NewLabel2.caption:=buf1; NewEdit2:=tedit.create(self); NewEdit2.parent:=self; NewEdit2.left:=300; NewEdit2.top:=70; NewLabel3:=Tlabel.Create(self); NewLabel3.parent:=self; NewLabel3.Left:=100; NewLabel3.top:=90; NewLabel3.caption:=buf2; NewEdit3:=tedit.create(self); NewEdit3.parent:=self; NewEdit3.left:=300; NewEdit3.top:=110; NewLabel4:=Tlabel.Create(self); NewLabel4.parent:=self; NewLabel4.Left:=100; NewLabel4.top:=110; NewLabel4.caption:=buf3; NewComboBox1:=Tcombobox.create(self); NewComboBox1.parent:=self; NewComboBox1.left:=300; NewComboBox1.top:=90; NewComboBox1.items.add('да'); NewComboBox1.items.add('нет'); inc(i); end; closeFile(f); end; end; end; procedure TForm1.Button1Click(Sender: TObject); var i:integer; FileName:string; f:TextFile; begin for i:=0 to componentCount-1 do begin If components[i] is Tedit then begin FileName:='Otvet.txt'; AssignFile(f,FileName); Append(f); Writeln(f,Tedit(Components[i]).Text) end; begin if components[i] is TCombobox then begin FileName:='Otvet.txt'; AssignFile(f,FileName); Append(f); Writeln(f,TCombobox(Components[i]).Text); CloseFile(f); end; end; end; end; end.
|
|