Sorry to resort to asking this, as the answer must surely be an obvious one I am missing.
I am using TFileListBox with Lazarus 2.0.10 (also tried with 2.0.4) to show files in a folder to the user.
When the user clicks a file, I want to load the content of it into TMemoryStream and show it in Memo1. Super simple.
Yet for some reason, the program says it is unable to open the file.
Unable to open file "C:\temp\test.html": The system cannot find the file specified.
Press OK to ignore and risk data corruption.
Press Abort to kill the program.
procedure TForm1.FileListBox1Click(Sender: TObject);
var
EncodedStream : TFileStream;
SelectedFile : string;
begin
SelectedFile := ExpandFileName(Filelistbox1.Items[FileListBox1.ItemIndex]); // THIS WAY CAUSES THE ERROR TO BE RAISED BELOW
// SelectedFile := 'C:\temp\test.html'; // YET IF I HARD CODE THE EXACT SAME PATH, AN ERROR IS NOT RAISED BELOW
try
EncodedStream := TFileStream.Create(SelectedFile, fmOpenRead or fmShareDenyNone); //*** ERROR IS RAISED HERE ***
EncodedStream.Position := 0;
Memo1.Lines.LoadFromStream(EncodedStream);
...
What on Earth am I missing? I've used ShowMessage(SelectedFile) and it returns exactly the right path and name. Are any of you able to download the attached sample project and get it to display a selected non-binary file in Memo1?