Because the file structure is quite complicated, it is also quite difficult, we can write information in a file in a file in a file without knowing the structure of a file that needs to be processed. The way to use flow has the following benefits: stream, simply, is a tool to establish an abstract processing data on an object-oriented basis. In the stream, some basic operations of processing data are defined, such as reading data, write data, etc., programmers are convection all operations without having to care about the true flow of the other data of the stream. The flow can not only handle files, but also process dynamic memory, network data, etc. The convenience of the flow is used in the program, and the writing program will greatly improve efficiency.
Programming environment is Delphi6
I, addinfo.exe should have the function:
1. You can choose the file you need to add information at will. You can use the driver list (DriveComboX1), the path list (DirectoryListBox1), the file list (fileListbox1), and associate them.
2, add information to the selected file.
1 First, it is first to determine whether the file is selected, and it is not possible to prompt the user to select a file that requires a specific need to add information. Set a global Boolean variable Nofile, assign the value when the main window is created: = false, that is, no selected file, then assign the value when selected files: = ture, call addition information when clicking the AddInfo button The file is the function, first so that the value of the Nofile is true, it is true that the code is executed, not prompting the user to select a file that requires a specific need to add information.
2 Judging the properties of the selected file, see if there is only read-only properties, and if there is, it will remove its read-only properties. IF (attribute = (attributes and fareadonly) THEN
Begin
Attributes: = Attributes-1;
Qudiaoread: = setFileAttributes (Pchar (filenamet), attributes;
END;
3 Judging whether the information you need to add (the price) is empty, if it is empty prompting the user to edit the information in the AddInfo group box.
4 Create a memory stream strStream, open a selected file TargetStream, and the file stream TargetStream to the end of the file TargetStream.seek (0, SOFROMEND); save the shading information to the file stream Memoname. Lines.SaveTream (Strstream); and the size of the STRSTREAM is tested, save the price information to memory streams. STRSTREAM (strStream); STRSTREAM); minus the size of the memory stream minus the size of the previous memory flow Temp can get the size of the price information in memory. Copy memory information to the file stream TargetStream (Strstream, Strstream.size); then add some control information to the file stream, // myinfosize is the size of the secondary tail, the NameSize shading is added to the file Location, the prices of Price is added to the file
as the picture shows:
Ii, readinfo.exe function
1. You can choose the file you need to add information at will. You can use the driver list (DriveComboX1), the path list (DirectoryListBox1), the file list (fileListbox1), and associate them. 2, read information from the selected file.
1 First, you have to determine if the file is selected, and you have not prompted that the user has to select a file that requires a specific need to add information. Set a global Boolean variable Nofile, assign the value when the main window is created: = false, that is, no selected file, then assign the value when selected files: = ture, call addition information when clicking the AddInfo button The file is the function, first so that the value of the Nofile is true, it is true that the code is executed, not prompting the user to select a file that requires a specific need to add information.
2 Open a selected file TargetStream, the positioning file stream TargetStream to the file's secondary information length TargetStream.seek; reading the length of the auxiliary information, according to the auxiliary information MyinFoSize You can find the location namesize of the shadow name. After reading the namesize, the file pointer actively moves to the price of the price Price, read the pricesize; so I can locate the name of the name according to NameSize, with Namesize-PriceSize to get the size of the shadow, Read the shadow-like structure variable addINfotype.vodname, read the price to the variable of the price to the structure, and addINfotype.vodname and AddInfotype.vodprice to the form of the form of the text editor In the box.
III, can also extend the function:
1. Because this is based on the operation of the stream, I can add any more information to the file, and we only need to add auxiliary information to OK.
2, we can define some default values so that the time can be saved.
3. You can define a tag (TAG) in the addition information so that you read whether this file is processed by this file in ReadInfo. !
Related Documents: Talking about "Flow" in Delphi Programming --- Chen Jing