Unit unit1; interfaceuses windows, messages, sysutils, variants, classes, graphics, controls, forms, dialogs, stdctrls; Type tform1 = Class (tform) memo1: tmemo; button1: tbutton; button2: tbutton; button3: tbutton; Procedure submit (Sender: tobject ); procedure button3click (Sender: tobject); end; var form1: tform1; implementation {$ R *. DFM} var mstream: tmemorystream; Procedure tform1.formcreate (Sender: tobject );// Program Create a file var strlist: tstringlist; begin strlist: = tstringlist. create; strlist. add ('aaaaaaa'); strlist. add ('bbbbbbbbbb'); strlist. add ('cccccccccc'); strlist. add ('ddddddddd'); strlist. savetofile ('C: \ temp \ test.txt '); strlist. free; {memory stream created at the same time} mstream: = tmemorystream. create; end; Procedure tform1.button1click (Sender: tobject); // read the file to memobegin mstream through the stream. loadfromfile ('C: \ temp \ test.txt '); {read the file into the memory stream} memo1.lines. loadfromstream (mstream); {load the memory stream to memo1} end; Procedure tform1.button2click (Sender: tobject); // read the content in the stream using the character pointer var PC: pchar; begin PC: = mstream. memory; {point the character pointer to the memory stream} showmessage (PC [0]); {A; first character} showmessage (PC [10]); {B; the first character of the second line. There are 8 characters in each line plus 10 characters including line breaks and carriage returns.} showmessage (PC [20]); {c} showmessage (PC [30]); {d} end; Procedure tform1.button3click (Sender: tobject); // read from stream to buffer var Buffer: array [0 .. 2] of char; {Character Buffer defined} begin mstream. seek (0, sofrombeginning); mstream. read (buffer, sizeof (buffer); showmessage (buffer); {AAA} mstream. seek (10, sofrombeginning); mstream. read (buffer, sizeof (buffer); showmessage (buffer); {BBB} mstream. seek (20, sofrombeginning); mstream. read (buffer, sizeof (buffer); showmessage (buffer); {CCC} mstream. seek (30, sofrombeginning); mstream. read (buffer, sizeof (buffer); showmessage (buffer); {DDD} {about seek function: parameter 1: offset is the offset; parameter 2: origin is the reference position of the pointer, there are three optional values: sofrombeginning, sofromcurrent, sofromend sofrombeginning: start as the benchmark. At this time, the parameter offset must be greater than or equal to 0; sofromcurrent: Base on the current position; sofromend: end with the parameter offset.