Delphi components read and write mechanism (1)
I. Introduction of Flow Objects (STREAM) and Writing Objects (FILER) In object-oriented programming, object data management has an important position. In Delphi, the support method of object-based data management is a major feature. Delphi is an object-oriented visual design combined with object-oriented language. The core of Delphi is a component. Components are one of the objects. The Delphi application is completely constructed by components, so developing high-performance Delphi applications will inevitably involve object data management technology.
Object-type data management includes two contents: ● Manage data with objects ● Management of various data objects (including objects and components)
Delphi classifies the object data management class as a Stream Object (Filer) and applies them to all aspects of the visual component library (VCL). They offer a rich functionality, Stream object, but also known as streaming objects, TSTREAM, THANDLESTREAM, TFILESTREAM, TMEMORYSTREAM, TFILESTREAM, TMEMORYSTREAM, TFILESTREAM, TMEMORYSTREAM, TRESOURSTREAM, and TBLOBSTREAM, and the like. They represent the ability to store data on various media, which abstracts the management operations of various data types (including objects and components) in memory, existence, and database fields, and makes full use of object-oriented technology Advantages, applications can be quite easily copied in various Stream objects. Read and write objects include TFiler objects, Treader objects, and twriter objects. TFiler objects are the base objects read and written, and the main Treader and Twriter are used in the application. Treader and Twriter objects are inherited directly from TFiler objects. The TFiler object defines the basic properties and methods of the FILER object. Filer objects mainly complete two major features: ● Access form files and components in the form file ● Provide data buffering, speed data read and write operations
In order to have a sense of sensibility to stream objects and read and write objects, first look at an example. a) Write file procedure tFomr1.writeData (sender: TObject); r; var filestream: tfilestream; mywriter: twriter; i: integerBegin filestream: = tfilestream.create ('c: /test.txt' ,fmopenwrite); // creation File current object MyWriter: = twriter.create (fileStream, 1024); // Put myWriter and FileStream; write a mywriter. WriteListBegin; // Write list Start flag for i: = 0 to memo1.lines.count-1 do mywriter. WriteString (Memo1.Lines [i]); // Save the MEMO component Chinese information to the MyWriter.writelistend; // Write list End Sign FileStream.seek (0, SOFROMBEGINNING); // File Streaming Objects Penno Move to Flow starting position Mywriter.free; // release Mywriter objects FileStream.free; // release FileStream object End; b) reading a file procedure TForm1.ReadData (Sender: TObject); Var FileStream: TFilestream; myreader: TReader; Begin FileStream: = TFileStream.create ('c: /test.txt' ,Fmopenread); MyReader: = Trreader.create (filestream, 1024); // Punch MyReader and FileStream to myReader.ReadlistBegin; // Start the list of writes to read Out of Memo1.Lines.clear; // Clear the text content of Memo1 components While not myreader.endoflist do // Note a method of Treader: endoflist begin memo1.lines.add (myReader.ReadString); // Put the read string Add to MEMO 1 component end; myReader.readlistend; // End the write list end flag reads myReader.Free; // Release the MyReader object filestream.free; // Release the FileStream object END; the above process, one is a write process, The other is a read process. Write the process through TWRITER, using TFileStream to store content (text information) in a MEMO as a binarily on disk. The read process is just contrary to the write process. Through TREADER, TFileStream uses TFileStream to convert the contents in the binaries into text information and displayed in MEMO. The running program can be seen that the read process is faithfully restores the information saved by the write process. The figure below describes the relationship between data objects (including objects and components), stream objects, and read and write objects. (A) It is worth noting that reading and writing objects, such as TFiler objects, Treader objects, and Twcriper objects, etc., are often used by application writers, which are usually used to read and write components, which is read and write component mechanism It plays a very important role in it. For streaming object Stream, there are very detailed introductions, and TFiler objects, Treader objects, and TWRITER objects, especially component read and write mechanisms, this article will be tracked by VCL original code. An analysis of the component read and write mechanism.