Mega Code Archive

 
Categories / Delphi / Files
 

Reading a locked or busy file

Title: Reading a locked or busy file Question: There is another article posted here that explains how to do this... but I couldn't get it to work on Win98 with Delphi5, so here's my solution to read from a file that is busy or locked. Answer: To use this you need an OpenDialog component, RichEdit component and a BitButton on a form. procedure TForm1.BitBtn1Click(Sender: TObject); var Buffer: string; Stream: TFileStream; DataLoader : TStringList; begin DataLoader := TStringList.Create; OpenDialog1.Execute; Stream := TFileStream.Create(OpenDialog1.FileName, fmShareDenyNone); SetLength(buffer, Stream.Size); Stream.Read(Buffer[1], Stream.Size); DataLoader.SetText(PChar(Buffer)); Stream.Free; RichEdit1.Text := DataLoader.Text; //this really isn't necessary, just //used it to 'see' the contents. end;