[Lazarus] View Graphic File

Allan E. Registos allan.registos at smpc.steniel.com.ph
Thu Feb 20 07:43:41 CET 2014


Hi all,

A noob question, I have trouble trying to port an existing vb.net
snippet to pascal. 
Can anyone provide a code snippet where we can download and view a file
from a Database?  A binary(jpeg/pdf file) was uploaded to a database
table. The code will just download the file uploaded and view it.

In vb.net this can be done:

      /      if conn.State = ConnectionState.Closed Then conn.Open()//
//            sql = "Select binfile from graphicfiles WHERE id=" & id//
//
//            cmd = New NpgsqlCommand(sql, conn)//
//
//            Dim fileData As Byte() = DirectCast(cmd.ExecuteScalar(),
Byte())//
//
//            Dim sTempFileName As String = Path.GetTempPath & "\" &
sFileName//
//
//            If Not fileData Is Nothing Then//
//
//                'Read image data into a file stream //
//                Using fs As New FileStream(sTempFileName,
FileMode.OpenOrCreate, FileAccess.Write)//
//                    fs.Write(fileData, 0, fileData.Length)//
//                    'Set image variable value using memory stream. //
//                    fs.Flush()//
//                    fs.Close()//
//                End Using//
//
//                Process.Start(sTempFileName) 'Open file//
//
//            End If//
/
Thanks,,
Allan
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140220/36a86123/attachment-0002.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4267 bytes
Desc: S/MIME Cryptographic Signature
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20140220/36a86123/attachment-0002.bin>


More information about the Lazarus mailing list