Working on a program that needs to open a file, read the contents which is a number, save the content as an integer in the program, edit the number by one and then save in the number in the file once more.

Pascal or Delphi? What do you have so far, and where are you stuck?

Pascal... Have nothing thus far but this. But it was only created as a test extract.
Application.Initialize; Application.CreateForm(TForm1, Form1); Application.Run; d:=1; Assign(Counter,'C:\check.txt'); Rewrite(Counter,d); close(counter); d:=d+1;
It all seems basically wrong and am pretty much stuck from the start so all help will do.

What you posted is Delphi code, but those functions still work. The following is a modified example from Delphi's Help to write a value to a text file:

var
  F: TextFile;
  d: Integer;
begin
  d := 1;
  AssignFile(F, 'C:\check.txt');
  Rewrite(F);
  Writeln(F, IntToStr(d));
  CloseFile(F);
end;

Now to extract it from the file, put in array then increase the value by one and finally save it back to the file.

Try it. You can find lots of examples in the help file.

I get run time error(104). Here's code:
`

var User: array of UserRecord;
     var
    F: TextFile;
    d,count: Integer;
   Procedure readcounter;
begin
    AssignFile(F, 'C:\check.txt');
    Rewrite(F);
    while not eof(f) do
    readln(f,d);<----- error pointed to here
    closefile(f);
    end;
    Procedure editcounter;
    begin
    d:=d+1;
    assign(f, 'C:\check.txt');
    rewrite(f);
    writeln(f, IntToStr(d));
//Writeln(F, IntToStr(d));
    CloseFile(F);
    end;
 Procedure checkdata;
 begin
 for count:= 1 to (d) do
 with User[d] do
 if (username = Edit1.text) and (useremail = edit3.text) and (Rname = edit4.text) and (Remail = edit6.text) then
 showmessage('Certain Fields are already taken please re-check and try again')
 else
   username := Edit1.text;
   userpassword := Edit2.text;
   useremail := edit3.text;
   Rname := Edit4.text;
   Rpassword := Edit5.text;
   Remail := Edit6.text;
   application.terminate;
 end;
{ TForm1 }


{ TForm1 }

procedure TForm1.Button1Click(Sender: TObject);
begin
  readcounter;
  checkdata;
  editcounter;
end;

`

Rewrite sets the file pointer to the beginning of the file for writing. Since you want to read, use Reset.

now its saying raised exception class'External: SIGSEGV'. Then points to line in control.inc
if TMethod(@Self.GetTextBuf).Code = Pointer(@TControl.GetTextBuf)

Step through it with the debugger and see where it fails in your code.

how does one go about that...

Didn't help... Really couldn't understand wat the man was saying at all

I'm going through and it points to this in my lpr

`begin<-------- pointed to here
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;

end.`

stepped over it and the assembler popped up with this:
System_FPC_CPUINIT (7)
System_FILLCHAR$formal$LONGINT$BYTE

Stepped again and got this:
fpc_initializeunits
and then pointed to this line saying:
0040c7A3 8b1dd0bd5600 mov

Step over then it points to line 2 in lpr

Set a breakpoint (using F5) on the first line in readcounter and start from there.

ok did that, didn't work but i think i've found the main cause of the problem by taking apart and executing each procedure individually. See below:

  Procedure checkdata;
 begin
 for count:= 1 to (d) do
 with User[d] do
 if (username = Edit1.text) and (useremail = edit3.text) and (facebookname = edit4.text) and (facebookemail = edit6.text) then
 begin
 showmessage('Certain Fields are already taken please re-check and try again');
 end
 else
   username := Edit1.text;
   userpassword := Edit2.text;
   useremail := edit3.text;
   facebookname := Edit4.text;
   facebookpassword := Edit5.text;
   facebookemail := Edit6.text;
   application.terminate;     

`
now the block that is causing the problem is

username := Edit1.text;
   userpassword := Edit2.text;
   useremail := edit3.text;
   facebookname := Edit4.text;
   facebookpassword := Edit5.text;
   facebookemail := Edit6.text;
   application.terminate;      
 end;`

Don't know what exactly is the problem, maybe a conversion needs to be done or data types changed or something. Would love to dabble with it now but i have to attend to stuff. But if you do know what to do let me know, Thanks.

for count:= 1 to (d) do with User[d] do

If User is an open array, then the count should be from 0 to d - 1. Apart from that, did you specify a length for the array using SetLength ?

did not use setlength and i change the count to o to d-1.. didn't help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.