so I've written this code which allows the user to search for a text file with a specific name, then enter the first name from the text file and actually edit what's written in that line. i.e. search for a text file called lions, and then edit the line where the name equals Michael.\ the only problem is that while it is edited the name just writes over what was previously there. What I mean is that if the original first name is Alexander, and then I edit that record to change that name to mike, the text file will keep the remaining letters so that the name in the text file is Mikeander. It kept the remaining letters. This happens for all entries in the record.
type
TCustomer = Record
FirstName : String[15];
LastName : String[15];
EventDate : String[15];
SeatNumber : String[100];
PhoneNumber : String [100];
Adress : String[100]
end;
var
Form4 : TForm4;
FirstName : string;
LastName : String;
EventDate : String;
SeatNumber : String;
PhoneNumber : String;
Adress : String;
begin
usersFilename := Inputbox('Which event needs its details edited?', '', '');
oldname := inputbox('Old Name','Input old name','');
newname := inputbox('New Name','Input new name','');
AssignFile(myFile, usersFilename);
Reset(myFile);
//Find the right record position by searching the file for the namne
count := 0;
while not Eof(myFile) do
begin
Read(myFile, Customer);
if Customer.FirstName = oldname then
recordNumber := count;
count := count+1;
end;
//Seek finds that record in the file and points at it, the read will read the current record
Seek(myFile, recordNumber) ;
Read(myFile,Customer) ;
//Set the new name for that record into our customer record
Customer.FirstName := newName;
Customer.LastName := Inputbox('Last Name', '', '');
Customer.EventDate := Inputbox('Event Date', '', '');
Customer.SeatNumber := Inputbox('Seat Number', '', '');
Customer.PhoneNumber := Inputbox('Phone Number', '', '');
Customer.Adress := Inputbox('Adress', '', '');
//read moves to the next record, so we have to go back again to the original record, then write
Seek(myFile, recordNumber);
//Write the current record which just has the name updated
Write(myFile, Customer);
showmessage('Successfully updated name');
CloseFile(myFile);
end;
If you could tell me how to make sure it completely removes the original word, instead of just mashing it together with the new word I would greatly appreciate it. Thanks