Hi Folks,
i'm new to the Forum, and pascal in general.
I'm coming from a 18-years background of Visual Basic 6 (classic, not .NET), and had to switch to FPC/Lazarus (reasons for it don't matter now).
I have an issue which puzzles me right now.
I have a PChar, which i pass to a Quicksort-Function to get it sorted
e.g.:
Source='klgbhter'
desired Result='behklrt'
I know that it works with an array, so that's not the issue, but since my other code uses PChar, i didn't want to change it to an array.
Never mind that an array of char is basically the same as a PChar (the array-variable is a pointer to the first element of the array, but it's still a pointer).
My first try was something along the lines
Var
ch:=Char;
//.......
//Let's say i want to swap the third character with the fifth of source
ch:=MyPChar[2];
MyPChar[2]:=MyPChar[4];
MyPChar[4]:=ch;
Funny thing: The compiler's not complaining, but line 6 causes everything to go KABOOM!
I tried with memcpy, memmove, Move and what not
Since in Visual Basic i never had to bother with Memory-Management and pointers i'm kind of stuck.
I don't have a degree in computer science and i'm definitely not a Pro in programming (i'm just a hobby-programmer), i don't even know the difference what the stack and the heap is
(but wouldn't mind someone explaining that to me, or i'll just look it up on Wikipedia
)
I remember finding a thread on this forum during my research, where one of the Administrators even mentioned something along the lines, that in FPC/Lazarus you cannot modify a string in that way, but for the life of me i can't find that thread (i think it was from 2013).
Is that true?
Any ideas how to achieve what i want?