This is a small sample program that demonstrates one way to import image data from external sources and save in a blob field of a table.
The table with images is displayed in XBrowse.
1) Drag and Drop: Any image file can be dragged and dropped on the required row of XBrowse. The image data read from the file is saved to the blob field.
2) Copy and Paste:
(a) Copy any image file in the file explorer and paste in the required cell of xbrowse.
(b) Copy any open image from an Internet browser or from any other source like word and paste in the cell.
- Code: Select all Expand view
#include "fivewin.ch"
function Main()
local oCn, oRs, oDlg, oBar, oFont, oBrw
oCn := FW_DemoDB()
oRs := oCn:wwonder2
DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
DEFINE DIALOG oDlg SIZE 600,350 PIXEL TRUEPIXEL FONT oFont RESIZABLE
@ 40,20 XBROWSE oBrw SIZE -20,-20 PIXEL OF oDlg ;
DATASOURCE oRs ;
COLUMNS "NAME", "IMAGE" ;
LINES NOBORDER
WITH OBJECT oBrw
:nEditTypes := EDIT_GET
:lCanPaste := .t.
:Image:nDataBmpAlign := AL_CENTER
:bDropFiles := { |r,c,aFiles| oBrw:SetPos( r, , .t. ), ;
oBrw:Image:VarPut( MemoRead( aFiles[ 1 ] ) ) }
//
:CreateFromCode()
END
@ 02,20 BTNBMP PROMPT "PASTE" SIZE 76,36 PIXEL OF oDlg FLAT ;
ACTION ( oBrw:GoToCol( "image" ), oBrw:Paste() )
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT DragAcceptFiles( oBrw:hWnd, .t. )
RELEASE FONT oFont
oCn:Close()
return nil
FW MariaRowSet is used in the sample. But the same sample works the same way with DBF, Array, ADO RecordSet or Dolphin/MySql Query, by simply replacing "oRs" after DATASOURCE with Alias(), array, RecordSet or oQry, as the case may be. We used the fields "NAME" and "IMAGE" in the above example. You may replace with the field names in your table where necessary.