f_getblobfromfile.srf 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. $PBExportHeader$f_getblobfromfile.srf
  2. global type f_getblobfromfile from function_object
  3. end type
  4. forward prototypes
  5. global function integer f_getblobfromfile (ref blob arg_bdata, string arg_filename, ref string arg_msg)
  6. end prototypes
  7. global function integer f_getblobfromfile (ref blob arg_bdata, string arg_filename, ref string arg_msg);//f_getblobfromfile(arg_bdata,arg_filename,arg_msg)
  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