f_filetoblob.srf 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. $PBExportHeader$f_filetoblob.srf
  2. global type f_filetoblob from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_filetoblob (string arg_filepathname, ref blob arg_blobdata, ref string arg_msg)
  6. end prototypes
  7. global function integer f_filetoblob (string arg_filepathname, ref blob arg_blobdata, ref string arg_msg);//读入数据
  8. long flen,loops,ls_i,bytes_read,new_pos,rslt=1,li_FileNum
  9. blob b_dtdata_p,tot_b
  10. flen = FileLength(arg_filepathname)
  11. li_FileNum = FileOpen(arg_filepathname, StreamMode!, Read!, LockWrite!)
  12. if li_FileNum=-1 then
  13. rslt=0
  14. arg_msg='打开文件'+arg_filepathname+'操作失败!'
  15. fileclose(li_FileNum)
  16. goto ext
  17. end if
  18. IF flen > 32765 THEN
  19. IF Mod(flen, 32765) = 0 THEN
  20. loops = flen/32765
  21. ELSE
  22. loops = (flen/32765) + 1
  23. END IF
  24. ELSE
  25. loops = 1
  26. END IF
  27. new_pos = 1
  28. FOR ls_i = 1 to loops
  29. bytes_read = FileRead(li_FileNum, b_dtdata_p)
  30. if bytes_read=0 then
  31. rslt=0
  32. arg_msg='读取文件'+arg_filepathname+'操作失败!'
  33. fileclose(li_FileNum)
  34. goto ext
  35. end if
  36. tot_b = tot_b + b_dtdata_p
  37. NEXT
  38. fileclose(li_FileNum)
  39. arg_blobdata=tot_b
  40. ext:
  41. return rslt
  42. end function