Mega Code Archive

 
Categories / Delphi / Examples
 

Textinsert

inserting contents of a file at current position in TMemo Question: How can I insert the contents of a file at the current position in a TMemo component? Answer: Use a TMemoryStream to read the file, then use the TMemo's SetSelTextBuf() method to insert the text; var TheMStream : TMemoryStream; Zero : char; begin TheMStream := TMemoryStream.Create; TheMStream.LoadFromFile('C:\AUTOEXEC.BAT'); TheMStream.Seek(0, soFromEnd); //Null terminate the buffer! Zero := #0; TheMStream.Write(Zero, 1); TheMStream.Seek(0, soFromBeginning); Memo1.SetSelTextBuf(TheMStream.Memory); TheMStream.Free; end;