A: This reads the autoexec.bat file into a memory block referenced by a PChar. Then, it is parsed, line by line, into a list box.
(Yes. I know that listbox1.items.LoadFromFile('c:\autoexec.bat'); is simpler, but this is an exercise in PChar use.)
procedure TForm1.Button1Click(Sender: TObject);
var
f: file;
pBeginString, pEndString, pTemp: PChar;
scratch: array[0..255] of char; {Automatically gets memory allocated
for it.}
LengthOfFile: integer;
begin
{Get the information.}
AssignFile(f, 'c:\autoexec.bat');
{Because this is not a text file type, the record size is 1
(char)}
Reset(f, 1);
LengthOfFile := FileSize(f) + 1; {Add one for the null terminator.}
pBeginString := AllocMem(LengthOfFile); {Zeros the memory also.}
BlockRead(f, pBeginString^, LengthOfFile - 1);
CloseFile(f);
pTemp := pBeginString;
inc(pTemp, LengthOfFile);
{Parse the strings into the Listbox.}
repeat
pEndString := StrPos(pBeginString, #13#10);
{carriage return/line feed}
listBox1.items.add(StrPas(StrLCopy(scratch,
pBeginString, pEndString - pBeginString)));
inc(pBeginString, pEndString - pBeginString + 2);
until pBeginString >= pTemp - 2;
dec(pTemp, LengthOfFile);
FreeMem(pTemp, LengthOfFile);
end;