| | |
Procedure for deleting array content
Please support our Pascal and Delphi advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
Hello, guys!
I have to make a program with the following features.
- array of records - a procedure/function to ADD data into the array
I did this one and I think it is working fine!
- a procedure/function to DELETE data from the array
I have problems with this procedure. It doesn't work when I try to delete the data in the first position of the array. Here's what I did so far: If you have some ideas, please let me know. Thanks in advance!
I have to make a program with the following features.
- array of records
Pascal Syntax (Toggle Plain Text)
TYPE employeeRecord = RECORD name: STRING; surname: STRING; age: Integer; END; employeeRecords = ARRAY OF employeeRecord ;
I did this one and I think it is working fine!
- a procedure/function to DELETE data from the array
I have problems with this procedure. It doesn't work when I try to delete the data in the first position of the array. Here's what I did so far:
Pascal Syntax (Toggle Plain Text)
PROCEDURE delete(VAR records: employeeRecords); VAR n, j: Integer; nameDel: STRING; BEGIN Write('Name: '); Readln(nameDel); n := 0; WHILE (records[n].name <> nameDel) AND (n < High(records)) DO BEGIN inc(n); END; IF records[n].name <> nameDel THEN BEGIN Writeln('That employee could not be found!'); Writeln; END; IF records[n].name = nameDel THEN BEGIN FOR j := n TO High(records)-1 DO BEGIN records[j].name := records[j+1].name; records[j].surname := records[j+1].surname; records[j].age:= records[j+1].age; SetLength(records, High(records)); // MAYBE THIS LINE IS NOT CORRECT END END END;
Last edited by simps0n; Dec 5th, 2007 at 12:02 pm.
The SetLength should not be in the loop, but after it. Other than that it looks fine to me.
BTW. You should be able to replace lines 27..29 with just
Don't know why you are using all-caps keywords, but it sure is anachronistic (a hold-over from brain-damaged BASIC users). I've not changed the functionality of your code here. Just structured it a little better...
Hope this helps.
BTW. You should be able to replace lines 27..29 with just
records[j] := records[j+1];Don't know why you are using all-caps keywords, but it sure is anachronistic (a hold-over from brain-damaged BASIC users). I've not changed the functionality of your code here. Just structured it a little better...
Pascal Syntax (Toggle Plain Text)
PROCEDURE delete(VAR records: employeeRecords); VAR n, j: Integer; nameDel: String; BEGIN Write('Name: '); Readln(nameDel); n := 0; WHILE (records[n].name <> nameDel) AND (n < High(records)) DO Inc(n); IF records[n].name = nameDel THEN BEGIN FOR j := n TO High(records)-1 DO records[j] := records[j+1]; SetLength(records, High(records)) END ELSE BEGIN Writeln('That employee could not be found!'); Writeln END END;
![]() |
Similar Threads
- Prblem with removing duplicates entries in a list. (Pascal and Delphi)
Other Threads in the Pascal and Delphi Forum
- Previous Thread: trying to use one form to open another form
- Next Thread: POSIBLE, POP3 indy using port 995
| Thread Tools | Search this Thread |






