Okay so, thanks for the help, people. I appreciate you taking the time to look over my terrible, terrible procedures.
Just some answers and stuff.
1) I have to use custom sort/search routines because that's in the task brief. I really really wish I didn't have to because I've spent so much time having trouble with them.
And do you really like memory corruption? Where are these lists and local objects free'd? And should the objects be local? (I don't think so....)
-snip-
2) I don't know what you mean by "where are the lists free'd". We've not been taught anything remotely similar to that, and a quick google showed no hint of what that might entail or look like, even on the pascal wiki
3) The objects below should be local because they're only used in that procedure. Why would they be global? They're temporary holders to make the initialisation easier to read.
1.I can see that you sort function is a complete mess
CurrentVal:= List[CurrentPtr];
Pointer:= CurrentPtr-1;
while (pointer>=0) and (List[pointer].GetID() > CurrentVal.GetID) do
begin
List[Pointer+1]:=List[Pointer]; // you are overwriting the next without saving it.
pointer:=Pointer-1 ;
end;
List[pointer+1]:=CurrentVal;
4) Isn't it not overwriting the next without saving because list[pointer+1] = list[currentPtr], which was saved to currentVal?
2.also you are repeating the same code 3 times (not good).
5) I can't really see any other way to do it, seeing as all 3 are sorting different types of list, so the parameters have to be set differently.
3.binarySearch_p uses recursion which I really dislike; and can be changed to while/for loop.
4.findPID_real is practically the same as binarySearch_p (but with the list locally defined).
6) findPID_real is actually the replacement for binarySearch_p. I fail to see how it's at all the same, binarysearch_p being a recursive binary search, and findPID_real being a plain linear search.
my advice is to rewrite the entire code with the consideration of :
1.Create a custom class list, with the necessary function (sort, find, Add, Del, Clear...).
2.Try not use generics.
3.When creating a sort function use the builtin sort and pass your TCompareFunc; Take look at this
4.Try not to duplicate the same or almost the same code.
7) I don't know what a custom class list is or why it would help, and I'm extremely too far into the project to rewrite everything from scratch.
8( What's a generic and why is it bad?
Again, thanks for taking the time to offer me help on all this.