Page 1 of 1

Drag and drop image resources

Posted: Tue Aug 14, 2018 2:53 pm
by Adolfo
Hi everybody

I need to drag and drop and image on an IMAGE resource, then replace a mysql blob field with the "new" image.

Found something in the forum, but it does not work

Code: Select all

REDEFINE IMAGE oImage FILE "nula.jpg"      ID 101 OF oFldTra:aDialogs[ 4 ] UPDATE


      oImage:bDropFiles := { |r,c,aFiles| ;
      If( Lower( cFileExt( aFiles[ 1 ] ) ) $ "jpg,jpeg", ;
         ( oImage:LoadImage( nil, aFiles[ 1 ] ), oImage:Refresh() ), ;
         MsgInfo( "No es un archivo de imagen permitido", aFiles[ 1 ] ) ) }

   .......
  ACTIVATE DIALOG odlgTrabaja CENTERED ON INIT DragAcceptFiles( oImage:hWnd, .T. )
 
I can drop the file into the image, but it doesn't update

Any help will be appreciated.

Fom Chile
Adolfo

Re: Drag and drop image resources

Posted: Tue Aug 14, 2018 7:19 pm
by cdmmaui
Hello Adolfo,

We are looking for the same solution. Our customer would like to be able to Drag and Drop images, documents and/or e-mails to a specific record.

Dear Antonio and Rao, is this possible?

Re: Drag and drop image resources

Posted: Wed Aug 15, 2018 1:28 pm
by nageswaragunupudi
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

#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.

Image

Re: Drag and drop image resources

Posted: Wed Aug 15, 2018 2:03 pm
by cdmmaui
Dear Rao,

Awesome! Thank you!

Would this work the same if I wanted to attach other document types such as PDF, Word, XLS, Email message, etc.?

Also, I would need to be able to add multiple documents to a single record and NOT overwrite the existing data.

Thanks again for your help!!!

Re: Drag and drop image resources

Posted: Wed Aug 15, 2018 2:10 pm
by nageswaragunupudi
In principle, Yes.

Depending on how we want to store the dropped files or their contents in the target database, we need to provide suitable code for the bDropFiles codeblock or handle the paste object.