Quote Originally Posted by Chebmaster
Things like this
[pascal]while (IText <Length> #32) do
begin
Part := Part+Text[IText]; [/pascal]
kill performance on the spot. Brutally.

EACH time you add a char to a string, a call to realloc its memory is performed. So you can imagine how "fast" will this code execute.

Ideally, you should make two passes. The first one determines subsstring lengths and positions, the second pass allocates memory by calling SetLength for destination strings (once!) and copies the characters.
Just to inform I made the optimization of that code

I'm allocating a big block to build the string Part, and then I cut it creating another string with the standard Copy() function. In total I make just two allocations in that function, and the speed of the program didn't changed significantly on my 4 years old computer. That should mean using Part := Part+Text[IText] is not a brutal performance killer as suggested. Maybe it is already being optimized by the compiler.

Anyway, that helped me to clear a little my code. Thanks.