Database application development technology Delphi provides Visual controls for Data Access (DataAccess) and Data Controls, which can easily and easily have a good interface and powerful database applications. For database applications involving image data (including graphic fields), such as personnel management information systems, etc., access technology of image data is a key. However, there are few information about the access, especially the image of the image below Delphi. Below, the author combines a simple example to illustrate.
1. Save image data 1. Create a list of databases containing the Graphic field. create database mydb.gdb create table myfrieds at WindowsISQ (or Databasedesktop) (name varchar (15) notnull, telephone varchar (12), address varchar (30), zipvarchar (8), picture varchar (15), image blob);
Where the Picture field is used to save the name of the image (including path), the image (graphic character) is used to store the image, and its data type is "blob".
2. Create a form and set the properties of each control in the form.
The main function of the form is to edit and save someone information. The image boxes you need to pay attention to the image boxes used must not be used with TDBIMAGE, the edit box should be used with TEDIT without using TDBEDIT, which is just the opposite of the image.
Among them, the properties of each major control are as follows: DataSource1.dataset: = table1; table1.databaseName: = mydb.gdb; table1.tablename: = myfriends; table1.active: = true; other property settings such as CAPTION Narrate.
3. The establishment of the data handler. (1) The processing of the image (.bmp file) is opened. Proceduretform1.pictopenbtnclick (sender: TOBJECT); begin opendialog1.execute; image1.picture.loadFromFile (OpenDialog1.FileName);
(2) Processing of image saving. The image saved handler completes the information edited by the form 1 including the image to the corresponding database, the key is to define a variable of a Graphic type and the variable is passed to the corresponding database to save. Specific procedures are as follows: procedureTform1.Savebtnclick (sender: TObject); var graphic1: TGraphic; begin graphic1: = TGraphic.Create; graphic1.loadfromfile (opendialog1.filename); table1.insert; table1.fieldbyname ( 'name') asstring:. = edit1.text; table1.fieldbyname ('telephon'). asstring: = edit2.text; table1.fieldbyname ('address'). asfloat: = Edit3.Text; table1.fieldbyname ('zip'). asfloat: = Edit4 .Text; Table1.fields [4] .ssign (graphic1); table1.post; graphic1.free; end; 2, image data read and browse in database data (including data of Graphic field), Delphi The superiority of object-oriented development tools with powerful code automatically generates the performance of the performance. If you don't exaggerate, you don't need a statement!
Establish a form and set the properties of each control.
The setting of the attribute of Table1 and DataSource1 is the same as the save section of the data, and the Database data is used with TDBEDIT and TDBIMAGE controls without TDIT and TIMAGE. Controls TDBEDIT and TDBIMAGE As long as the DataField property is set to its corresponding domain; the TDBNAVIGATOR's DataSouce property is set to DataSource1.