As Scoops says you need to open and close file only once. For example, If your database table has
many records, your code will open and close file multiple times and this will slow down your code.
In your example, "Rewrite" command open and empty file in every iteration
of your loop, this is the reason why is only last record survived.
You can use WriteLn instead of appending CRLF (#13#10) at the end of the string.
AssignFile(f, 'C:\MyFolder\MyFile.txt');
try
Rewrite(f);
while not Query.eof do begin
WriteLn(f, 'StringA: ' + Query.FieldByName('String_A').AsString);
WriteLn(f, 'StringB: ' + Query.FieldByName('String_B').AsString);
WriteLn;
Query.Next;
end; // while ...
finally
Close(f);
end;