Hello. The problem is as follows.

Data is entered into edit1 and edit2 , the data is entered into a text file. After that, the so-called "authorization" occurs, where in the edit1 (2) fields you need to enter data from those previously recorded in the text file. But here's the problem: edit'y perceive only 5 characters and, if the data from the text file is more or less than 5 characters, then the program does nothing. What can be done in this case?

unit Unit3; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm3 = class(TForm) Edit1: TEdit; Edit2: TEdit; Label1: TLabel; Label2: TLabel; Label3: TLabel; Edit3: TEdit; Label4: TLabel; Edit4: TEdit; Label5: TLabel; Edit5: TEdit; Label6: TLabel; Edit6: TEdit; Button1: TButton; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form3: TForm3; f:textfile; implementation uses Unit2, Unit4; {$R *.dfm} procedure TForm3.Button1Click(Sender: TObject); var s:string; begin if (edit1.Text='') or (edit2.Text='') or (edit3.Text='') or (edit4.Text='') or (edit5.Text='') or (edit6.Text='') then ShowMessage ('Шеф, всё пропало!') else begin AssignFile(f, 'a.txt'); Reset(f); // открыть файл append(f); // добавление в файл s:=edit1.Text+' '+edit2.Text+' '+edit3.Text+' '+edit4.Text+' Логин '+edit5.Text+' Пароль '+edit6.Text; writeln(f,s); CloseFile(f); // закрыть файл Form3.close; Form2.Visible:=True; end; edit1.Text:=''; edit2.Text:=''; edit3.Text:=''; edit4.Text:=''; edit5.Text:=''; edit6.Text:=''; end; procedure TForm3.Button2Click(Sender: TObject); begin Form3.close; Form2.Visible:=True; edit1.Text:=''; edit2.Text:=''; edit3.Text:=''; edit4.Text:=''; edit5.Text:=''; edit6.Text:=''; end; end. 

2:

 unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type TForm1 = class(TForm) Label1: TLabel; Label2: TLabel; Button1: TButton; Edit1: TEdit; Edit2: TEdit; Button2: TButton; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; f:textfile; implementation uses Unit2, Unit4, Unit8; {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var pos1:integer; pos2:integer; a:boolean; s,s1:string; s2:string; begin a:=false; If (edit1.Text='Admin') or (edit2.Text='Admin') then begin Form1.Visible:=false; edit1.Text:=''; edit2.Text:=''; Form8.Visible:=true; end else begin if (edit1.Text='') or (edit2.Text='') then ShowMessage ('Неправильный логин или пароль!') else begin AssignFile(f, 'a.txt'); Reset(f); // открыть файл while not Eof(f) do begin //Читаем очередную строку файла в переменную S Readln(f, S); pos1:=pos('Логин ',s); pos2:=pos('Пароль ',s); s1:=copy(s,pos1+6,5 ); s2:=copy(s,pos2+7,5) ; if (edit1.Text=s1) and (edit2.Text=s2) then a:=true; end; CloseFile(f); if a then begin Form1.Visible:=False; edit1.Text:=''; edit2.Text:=''; Form4.Visible:=true; end; end; end; end; procedure TForm1.Button2Click(Sender: TObject); begin Form1.Visible:=false; Form2.Visible:=True; edit1.Text:=''; edit2.Text:=''; end; 

Closed due to the fact that off-topic participants Kromster , aleksandr barakin , lexxl , user207618, user194374 Aug 17 '16 at 5:47 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - Kromster, aleksandr barakin, lexxl, Community Spirit, Community Spirit
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Very pleased with the combination Reset (f); // open the file append (f); // add to file - pincher1519
  • I thought about DotA (... lina characters ...) when I read, it's time to throw. - Gena Ant
  • @all: need a new "sheet" tag. - VladD

1 answer 1

  s1:=copy(s,pos1+6,5 ); s2:=copy(s,pos2+7,5) ; 

You are not embarrassed by the number 5 and the number of characters copied?

  • You look at the root ... Indeed, why only 5 characters are copied, no more or no less :-) - pincher1519