f_getblobfromfile_rpt.srf 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. $PBExportHeader$f_getblobfromfile_rpt.srf
  2. global type f_getblobfromfile_rpt from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_getblobfromfile_rpt (ref blob arg_bdata, string arg_filename, ref string arg_msg)
  6. end prototypes
  7. global function integer f_getblobfromfile_rpt (ref blob arg_bdata, string arg_filename, ref string arg_msg);//f_getblobfromfile
  8. long rslt=1
  9. long flen,li_FileNum,loops,ls_i,bytes_read,new_pos
  10. blob b_dtdata_p,tot_b
  11. SetPointer(HourGlass!)
  12. // Get the file length, and open the file
  13. flen = FileLength(arg_filename)
  14. li_FileNum = FileOpen(arg_filename, StreamMode!, Read!, LockRead!)
  15. if li_FileNum=-1 then
  16. rslt=0
  17. arg_msg='打开文件'+arg_filename+'操作失败!'
  18. fileclose(li_FileNum)
  19. goto ext
  20. end if
  21. // Determine how many times to call FileRead
  22. IF flen > 32765 THEN
  23. IF Mod(flen, 32765) = 0 THEN
  24. loops = flen/32765
  25. ELSE
  26. loops = (flen/32765) + 1
  27. END IF
  28. ELSE
  29. loops = 1
  30. END IF
  31. // Read the file
  32. new_pos = 1
  33. FOR ls_i = 1 to loops
  34. bytes_read = FileRead(li_FileNum, b_dtdata_p)
  35. if bytes_read=0 then
  36. rslt=0
  37. arg_msg='读取文件'+arg_filename+'操作失败!'
  38. fileclose(li_FileNum)
  39. goto ext
  40. end if
  41. tot_b = tot_b + b_dtdata_p
  42. NEXT
  43. arg_bdata=tot_b
  44. fileclose(li_FileNum)
  45. ext:
  46. return rslt
  47. end function