home *** CD-ROM | disk | FTP | other *** search
- function isole
- parameters tablename,fieldname
-
- * This routine checks to see if the given memo field
- * contains the OLE signature.
-
- * constants
- left_right = .f.
- right_left = .t.
- ole_signature = chr(21)+chr(28)
-
- fieldname = upper(fieldname)
-
- * open the table
- chan = fopen(tablename)
- if chan < 0
- return -1
- endif
-
- * check to make sure this is a FoxPro table
- onebyte = fread(chan,1)
- if asc(onebyte) <> 245
- =fclose(chan)
- return -4
- endif
-
- * throw away last update date
- junk = fread(chan,3)
-
- * get number of records
- four_bytes = fread(chan,4)
- num_recs = hex2int(four_bytes,right_left)
-
- * get first data record position
- two_bytes = fread(chan,2)
- data_start = hex2int(two_bytes,right_left)
-
- * get length of one data record
- two_bytes = fread(chan,2)
- rec_length = hex2int(two_bytes,right_left)
-
- junk = fread(chan,20)
-
- * get first field name
- fname = fread(chan,10)
- do while upper(fname) <> fieldname and not feof(chan)
- junk = fread(chan,22)
- fname = fread(chan,10)
- enddo
-
- * was the requested field in the table?
- if fname = fieldname
- junk = fread(chan,1)
-
- * check to see if this field is a memo field
- onebyte = fread(chan,1)
- if onebyte <> 'M'
- = fclose(chan)
- return -2
- else
- * we know that this field is a memo
-
- * open memo file
- mfile_name = left(tablename,len(tablename)-(len(tablename)-rat(".",tablename))) + "FPT"
- memo_file = fopen(mfile_name)
- if memo_file < 0
- =fclose(chan)
- return -7
- endif
-
- * get block size
- junk = fread(memo_file,6)
- two_bytes = fread(memo_file,2)
- block_size = hex2int(two_bytes,left_right)
-
- * get displacement of field in record
- four_bytes = fread(chan,4)
- field_disp = hex2int(four_bytes,right_left)
-
- * scan through each record to see if data is OLE
- * go to start of data
- = fseek(chan,data_start,0)
- * go to field location within record
- = fseek(chan,field_disp,1)
- for i = 1 to num_recs
- * get block number in memo file
- block_num = val(fread(chan,10))
- * if the memo is not empty
- if block_num > 0
- * go to the start of this memo (+8 is signature offset)
- = fseek(memo_file,(block_size * block_num)+8,0)
- * get signature
- two_bytes = fread(memo_file,2)
- if two_bytes <> ole_signature
- * This is not an OLE object. Get out.
- =fclose(chan)
- =fclose(memo_file)
- return -6
- endif
- endif
- * Go to next memo field
- = fseek(chan,rec_length - 10,1)
- endfor
- * if we got this far each memo had an OLE signature
- =fclose(chan)
- =fclose(memo_file)
- return 1
- endif
- else
- * requested field was not in the table
- =fclose(chan)
- return -5
- endif
-
-