This is one way of inserting BLOB in Delphi. There are several ways
to accomplish this task. This example is just one way of doing it.
This example is using the LoadFromFile method.
Create a table in InterBase with a field that can store non-text Blobs:
create table table1 (images blob sub_type 0);
-------------------------------------------------------------------------------------------------
* Put TQuery and a Button on the form.
* Set the TQuery's properties:
> Alias name to the BDE Alias pointing to the database.
> SQL to the sql statement to be executed,
i.e. select images from table1
> RequestLive to True.
> Active to true.
* Go back to TQuery component and double click which will bring up a window
titled "form1.query".
* Right click on the blank space of form1.query and choose add fields.
* Select images in the list and add.
* Double click on the TButton.
* Add the following lines
procedure TForm1.Button1Click(Sender: TObject);
begin
query1.append;
query1images.loadfromfile('c:testimage.bmp');
query1.post;
end;
Note: images is the field name defined as blob.
And c:testimage.bmp is where the location of the
image file to be inserted.
* Save the project/form/unit and Run.
* Click on the Button will insert a blob entry.
To verify the Blob is inserted:
* Drop a Tdatasource and TDBImage component on the form.
* Set the properties of Tdatasource:
> Dataset to "query1"
* Set the properties of TDBImage:
>Datasource to "datasource1"
>Datafield to images
* Save the project and run. You should see the images displayed.
Note: By default, DBImage will only display bitmaps.
Web: http://delphi.about.com
▻★★★ Blog sobre el lenguaje de programación delphi, incluye software, tutoriales, aplicaciones, videos, código fuente, trucos (about delphi, tips, tutorials, applications, source code, advanced programs, code snippets )
Suscribirse a:
Enviar comentarios (Atom)
Simulación del movimiento de los electrones en un campo electrico
Espectacular simulación realizada con OpenGL del movimiento de los electrones cuando atraviesan un campo eléctrico. Como muestra la image...
-
Espectacular simulación realizada con OpenGL del movimiento de los electrones cuando atraviesan un campo eléctrico. Como muestra la image...
-
Este programa sirve para calcular los valores de un resistor en función del color de las bandas de colores que lleva serigrafiadas en su s...
-
Los códigos QR son una forma eficiente de almacenar y acceder a información. Las ventajas de usarlos son: Facilidad de uso : Los códigos...
No hay comentarios:
Publicar un comentario