It works like this, I click on the button, it shows how many times it has, it saves it to a file, after I close the program, when I re-enter it, it saves that value, but when I press the button again, the counter is reset, how to continue the counting?
unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls; type TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; type TData = record Number: Integer; end; var Form1: TForm1; i:integer; Data: TData; F: File of TData; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); type TData = record Number: Integer; end; var Data: TData; F: File of TData; begin edit1.Text:=IntToStr(i); i:=i+1; AssignFile(F, 'C:\Data.dat'); Reset(F); Data.Number := StrToInt(Edit1.Text); Write(F, Data); CloseFile(F); end; procedure TForm1.FormCreate(Sender: TObject); begin AssignFile(F, 'C:\Data.dat'); Reset(F); Read(F, Data); Edit1.Text := IntToStr(Data.Number); CloseFile(F); end; end.