First, you need a cycle in which you search for the index of the whitespace character. In addition, think about the fact that not only a space can be at the end of a word, but several other different signs. For your task, using the Pos function does not make much sense. For example,
for I := 1 to length(s) do begin if (s[i] = ' ') or (s[i] = ',') or ... then ... end;
Secondly, the use of the functions copy, insert, delete is also meaningless. Since the string is represented by an array of characters, you only need to change the values by the index of the first letter of the word and your current index in the search minus one. In this way:
var c: char; firstLetter: integer;//в начале работы программы должна быть = 1 //(самому первому символу строки) ...//нашли пробел/другой символ c = s[firstLetter]; //сохраняем первую букву слова s[firstLetter] := s[i - 1]; //перезапиписываем первую букву последней s[i - 1] := c; //перезаписываем последнюю букву //сохраняем первую букву следующего слова, //не забыв проверить не вышли ли мы за пределы длины строки if (i + 1) <= length(s) then //если i + 1 будет больше, мы и так из цикла выйдем firstLetter = i + 1;
All this can still be flavored with checks of various kinds, when there are several spaces in a row, for example. Be careful with indexes, I could miss something somewhere, because I described just one of the solutions.