unit Unit1; {$mode objfpc}{$H+}interfaceuses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Menus, CRT;type { TForm1 } TForm1 = class(TForm) MainMenu1: TMainMenu; BWallet: TMenuItem; OpenWallet: TMenuItem; EditWallet: TMenuItem; procedure OpenWalletClick(Sender: TObject); private { private declarations } public { public declarations } end;Type STR = string; Walletrec = Record Balance,Addto,Remove : STR; WFile : Text; end;var Form1: TForm1; WalletV : WalletRec; ReadSTR : string;implementation{ TForm1 }procedure TForm1.OpenWalletClick(Sender: TObject);BEGIN ClrScr; Writeln('Please Wait...'); AssignFile(WalletV.WFile,'Wallet.dat'); While NOT FIleexists('Wallet.Dat') Do begin ClrScr; Writeln('You Do Not Have a wallet yet!'); writeln('Input your current wallet balance'); Readln(WalletV.Balance); Rewrite(WalletV.WFile); writeln(WalletV.WFile,WalletV.Balance); Closefile(WalletV.WFile); writeln('Your Wallet Has been saved!'); Delay(1000); ClrScr; end; ClrScr; Reset(WalletV.WFile); writeln('Current Balance:'); While NOT EoF(WalletV.WFile) Do begin Readln(WalletV.WFile,ReadSTR); writeln(ReadSTR); end;END;initialization {$I unit1.lrs}end.
Could you explain how to use the TEdit and Tlabel
Code: [Select]procedure TForm1.OpenWalletClick(Sender: TObject);BEGIN ClrScr; Writeln('Please Wait...'); AssignFile(WalletV.WFile,'Wallet.dat'); While NOT FIleexists('Wallet.Dat') Do begin ClrScr; Writeln('You Do Not Have a wallet yet!'); writeln('Input your current wallet balance'); Readln(WalletV.Balance); Rewrite(WalletV.WFile); writeln(WalletV.WFile,WalletV.Balance); Closefile(WalletV.WFile); writeln('Your Wallet Has been saved!'); Delay(1000); ClrScr; end; ClrScr; Reset(WalletV.WFile); writeln('Current Balance:'); While NOT EoF(WalletV.WFile) Do begin Readln(WalletV.WFile,ReadSTR); writeln(ReadSTR); end;END;
procedure TForm1.OpenWalletClick(Sender: TObject);BEGIN ClrScr; Writeln('Please Wait...'); AssignFile(WalletV.WFile,'Wallet.dat'); While NOT FIleexists('Wallet.Dat') Do begin ClrScr; Writeln('You Do Not Have a wallet yet!'); writeln('Input your current wallet balance'); Readln(WalletV.Balance); Rewrite(WalletV.WFile); writeln(WalletV.WFile,WalletV.Balance); Closefile(WalletV.WFile); writeln('Your Wallet Has been saved!'); Delay(1000); ClrScr; end; ClrScr; Reset(WalletV.WFile); writeln('Current Balance:'); While NOT EoF(WalletV.WFile) Do begin Readln(WalletV.WFile,ReadSTR); writeln(ReadSTR); end;END;
unit Mantrixs;{$mode objfpc}{$H+}interfaceuses Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Menus, StdCtrls;type { TForm1 } TForm1 = class(TForm) Button1: TButton; Edit1: TEdit; Label1: TLabel; MainMenu1: TMainMenu; WalletN: TMenuItem; OpenWallet: TMenuItem; EditWallet: TMenuItem; procedure FormCreate(Sender: TObject); procedure OpenWalletClick(Sender: TObject); private { private declarations } public { public declarations } end; Type Str = String; Walletrec = Record WFile,Balance,Addto,Remove : Str; end;var Form1: TForm1; WalletV : Walletrec;implementation{ TForm1 }procedure TForm1.FormCreate(Sender: TObject);beginend;procedure TForm1.OpenWalletClick(Sender: TObject);begin Label1.Caption := 'Input your current balance'; Button1.Click; walletv.balance := 'Edit1.txt';end;initialization {$I Mantrixs.lrs}end.
Thats how i learned to read from files and it works fine.
var F: TextFile; S: String;begin AssignFile(F,'test.txt'); Reset(F); //Open F for reading only while not EOF(F) do //as long as we are not at the end of the file do: begin readln(F,S); //read line from file writeln(S); //display line on the console end; CloseFile(F); ... AssignFile(F,'test2.txt'); //the rewrite() wil create the file and ope it for writing. //If the file already existed it will erase and then overwrite it's contents Rewrite(F); repeat write('Enter new line (empty line quits): '); readln(S); //read input from user writeln(F,S); //write input from user to file until S = ''; //until user enters an empty stringend;
While NOT FIleexists('Wallet.Dat') Do begin Writeln('You Do Not Have a wallet yet!'); writeln('Input your current wallet balance'); Readln(WalletV.Balance); Rewrite(WalletV.WFile); writeln(WalletV.WFile,WalletV.Balance); Closefile(WalletV.WFile); writeln('Your Wallet Has been saved!'); end;
rewrite(WalletV.WFile);
... if not FileExists('Wallet.Dat') then begin //code here to create the file and put initial content in it //if an error occurred display it and abandon end; ...
... Reset(WalletFile); while not EOF(WalletFile) do readln(WalletFile,S); //some more code end; ...
... Reset(WalletFile); // EOF might be true, and in that case we will never do a readln, so assign //empty value to S S := ''; if not EOF(WalletFile) do readln(WalletFile,S); //some more code end; ...end;