FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour XBROWSE <binary> problem
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
XBROWSE <binary> problem
Posted: Fri Jun 22, 2012 12:08 PM
Hi all,
I have xbrowse created with data received from the SQL SELECT statement.
In some cases in some columns in some row i get field data (field info) <binary>
Probably in some row of that column there is some binary characters.

My question is how to define that that column is only a sample text column.

Best regards,
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: XBROWSE &lt;binary&gt; problem
Posted: Fri Jun 22, 2012 12:16 PM

Same Question, but couldn't find out the reason for it :

viewtopic.php?f=3t=24050p=129498hilit=xbrowse+binary#p129498

Best Regards
Uwe

&&&

Since 1995 ( the first release of FW 1.9 )

i work with FW.

If you have any questions about special functions, maybe i can help.
Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: XBROWSE &lt;binary&gt; problem
Posted: Fri Jun 22, 2012 01:50 PM
avista

If you want to design a custom xBrowse .. you can define your standard columns and then insert your Binary Column at a specific column ( in this case column 5 ) and the Code Block allows you to Return any value you like to view in column 5.

Rick Lipkin

Code (fw): Select all Collapse
 ADD oCol TO oLbx AT 5 DATA {|x| x := _ChkComp(oRsRepair:Fields("cc"):Value) };
                   HEADER "Instructions" size 165
...
...

//-------------------
Static Func _ChkComp( cComplaint )

Local cName

cName := cComplaint

Return(cName)
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Sat Jun 23, 2012 03:07 PM
Hi Rick
And thanks for reply
I dont know the field names or sizes or types ... received from the SQL SELECT statement...
But that is not problem ...
Problem is that sometimes user put TAB key not SPACE ... and in XBROWSE that is BINARY valye.
See this sample.
Code (fw): Select all Collapse
#include "FiveWin.ch"
#include "xbrowse.ch"

function Main()

   local oDlg, oBrw

   DEFINE DIALOG oDlg SIZE 300, 200

   @ 0, 0 XBROWSE oBrw OF oDlg ;
          ARRAY { "Tom Jones", "Tom"+chr(32)+"Jones", "Tom"+chr(14)+"Jones" } ;
          AUTOCOLS

   oBrw:CreateFromCode()

   ACTIVATE DIALOG oDlg CENTER

return nil


In this case the row 3 have <binary> value.

Some help or sugestions ?

Best regards,
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Sun Jun 24, 2012 02:10 PM

If the value of a column is displayable text, it displays the text ( either in a single row or if space of the cell permits in multiple rows even ).

If the value contains non-printable characters, obviously it can not display it as text.

Still xbrowse makes an effort to examine if it is a valid image buffer. If it is a valid image buffer it displays the image.

Still after all efforts there are unprintable characters, it indicates that the value contains <binary> data. So that the programmer knows that his table contains some binary data and can provide an appropriate conversion function to display the data in a printable form.

Regards



G. N. Rao.

Hyderabad, India
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Mon Jun 25, 2012 03:01 PM
Hi Rao
Thanks for reply
It is not problem to create conversion function
For example

Code (fw): Select all Collapse
function Conversion(uData)

   local cReturn := ""
   local i       := 0

   for i = 1 to len(uData)
       if asc(substr(uData,i,1)) < 32
          cReturn := cReturn + "?"
        else
          cReturn := cReturn + substr(uData,i,1)
       endif
   next

return cReturn


But where and how to use that function in XBROWSE

Best regards,
Posts: 990
Joined: Thu Nov 17, 2005 05:49 PM
Re: XBROWSE &lt;binary&gt; problem
Posted: Mon Jun 25, 2012 03:06 PM

Avista;

Use Rick's suggestion. Simply replace your function into the code block for all columns.

Reinaldo.

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Mon Jun 25, 2012 03:27 PM

Like our friends suggested above, we need to provide our codeblock.
Several ways of doing it.
Example 1
If we are browsing fwh\samples\customer.dbf and we expect some control chars in the NOTES field
Method-1
@ 0,0 XBROWSE oBrw OF oWnd ;
COLUMNS "First", "Last", "City", "Notes" ;
< .... other clauses >
....
oBrw:Notes:bStrData := { || MyConvert( Eval( oBrw:Notes:bEditValue ) ) }

Method-2

@ 0,0 XBROWSE oBrw OF oWnd ALIAS "CUSTOMER" ;
COLUMNS "First", "Last", "City", { || MyConvert( FIELD->NOTES ) } ;
< .... other clauses >

Array Example:
Assuming we expect 3rd column to contain control chars
@ 0,0 XBROWSE oBrw ARRAY aData ;
COLUMNS 1, 2, { || MyConvert( oBrw:aRow[ 3 ] ) } ;
HEADERS ......<continue with other clauses )

OOPS example:
WITH OBJECT oBrw:AddCol
:bEditValue := { || MyConvert( FIELD->NOTES ) }
END

Regards



G. N. Rao.

Hyderabad, India
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Wed Jun 27, 2012 01:48 PM

Hi Rao,
Thanks verry much for reply.

One more Question please,
How to detect non-printable characters ? (control chars like you said) .
Less than 32 or ? (probably no ...CRLF chr(13)+chr(10) is not binary ... ?)
Which ASCII codes to control ? Is it good to replace them with "?" or ?
Or need i analize blocks ?

Thanks again for helping,
Best regards.

Posts: 2706
Joined: Fri Oct 07, 2005 01:50 PM
Re: XBROWSE &lt;binary&gt; problem
Posted: Wed Jun 27, 2012 02:27 PM

Avista

A quick question .. what is the field name of the binary column ? Generally Binary designates a 'file' of some sort stored in that field which is in hex .. it could be a document, picture, .pdf file ...

I don't think you will be able to determine what is in the binary field without some knowledge of the table.

Rick Lipkin

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Wed Jun 27, 2012 02:31 PM
avista wrote:Hi Rao,
Thanks verry much for reply.

One more Question please,
How to detect non-printable characters ? (control chars like you said) .
Less than 32 or ? (probably no ...CRLF chr(13)+chr(10) is not binary ... ?)
Which ASCII codes to control ? Is it good to replace them with "?" or ?
Or need i analize blocks ?

Thanks again for helping,
Best regards.


Please try using FiveWin function IsBinaryData( <cVar> ) --> .t. or .f.
Regards



G. N. Rao.

Hyderabad, India
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Fri Jun 29, 2012 08:42 AM
Hi
And thanks to all for reply

This funciion is working good BUT
Code (fw): Select all Collapse
FUNCTION MyBinaryConversion( cData )

local cVrati := ""
local cChar  := ""
local nAsc   := 0
local i      := 0

IF !IsBinaryData( cData )
   return cData
ENDIF

FOR i = 1 TO LEN( cData )
    cChar := SUBSTR( cData, i, 1 )
    nAsc  := ASC( cChar )

    IF nAsc <  32 .AND. ;
       nAsc <>  9 .AND. nAsc<> 10 .AND. nAsc<> 13 .AND. nAsc<> 26
       cVrati := cVrati + CHR( 127 )
     ELSE
       cVrati := cVrati + cChar
    ENDIF
NEXT

RETURN cVrati


BUT I HAVE OTHER PROBLEM

The database i use (.DBF) is created by SQL SELECT statement and i dont know the fieldnames ... (columns names)
I have try this code:

Code (fw): Select all Collapse
FOR i := 1 TO Fcount()
    IF !Empty( oCol := oBrw:oCol( oBrw:oCol(i):cHeader ) ) 
       IF FieldType( i ) == "M" .OR. ;
          FieldType( i ) == "C"
          oCol:bStrData := { || MyBinaryConversion( EVAL(oCol:bEditValue) ) }
       ENDIF
    ENDIF
NEXT


But in XBROWSE i have the same data in all columns (data from the last column)
Probably becouse at the end of FOR,NEXT ciclusulse 'i' have value of Fcount() and EVAL(oCol:bEditValue) return value of last column for all columns.
I cant use the stagement like this:
oBrw:bStrData := { || MyBinaryConversion( Eval( oBrw:bEditValue ) ) }
becouse like i said i dont know the column names.

I have try this:
Code (fw): Select all Collapse
FOR i := 1 TO Fcount()
    IF !Empty( oCol := oBrw:oCol( oBrw:oCol(i):cHeader ) )
       IF FieldType( i ) == "M" .OR. ;
          FieldType( i ) == "C"
          cField := oBrw:oCol(i):cHeader
          oBrw:oCol(cField):bStrData := { || MyBinaryConversion(EVAL(oBrw:oCol(cField):bEditValue)) }
       ENDIF
    ENDIF
NEXT


BUT THE SAME RESULTS all columns have the same value of the last column

I have no more solutions so
Please help

BEST best regards,
Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Wed Jul 04, 2012 06:59 AM

Hi,
I still need help ...
Regards,

Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Sat Jul 07, 2012 12:53 PM

?

Posts: 301
Joined: Fri Jun 01, 2007 09:07 AM
Re: XBROWSE &lt;binary&gt; problem
Posted: Tue Jul 10, 2012 08:21 PM

Everyone on vacation ?

Regards.

:)