Actually I'm thinking of abandoning the project. I think the best way of doing it is with a SQLLite but the learning curve on a database is pretty steep and I haven't been able to find a good example to start with.
Here is a suggestion which I don't really know how well it fits your requirements but, I am under the impression that you're trying to "massage" a whole lot of data until you get it the way you need it. If that is correct, you'd probably be well off installing a SQL based database system (such as Postgres), create simple programs to load the data into database tables and use SQL, first to see how all that data fits together and, finally generate an output file that is clean, easy to parse and, just the way you want it using SQL. Once you're there, writing a program that uses a clean, well organized and complete data file is often easy.
SQL is a powerful language, you can do in a few lines what would take hundreds, even thousands sometimes, of lines of Pascal code.
Yes, you'll spend a month (maybe a little more) getting a reasonable idea of how to use SQL but, overall, it's easy, interactive and, you can _see_ the results quickly. You can try a lot of things until you find the one way that works best.
A lot of programmers get trapped in the "when all you've got is a hammer, everything looks like a nail". Don't write code you don't need. Between AWK, SQL and a few custom little FPC programs you'd surprised how easily, quickly and little effort it may require to get to the final product.
Moral of that somewhat "lecture" is, add tools to your toolbox. You're having a hard time because of the method you've chosen. Don't give up on the goal, give up on the method. Time for a better one.
HTH.