Il seguente testo Š tratto dal manuale di TheDraw 4.62 e contiene alcuni esempi di gestione dei files binari. Faccio comunque notare che Binary Ansi Viewer *NON* Š basato in alcun modo su queste funzioni in quanto il suo funzionamento Š molto pi— complesso... ed ottimizzato! 8-) úÄÍþ³’ïþÍÄú of TwT ------------------------------------------------------------------------------- PROGRAMMING IN CLIPPER(TM) (courtesy of Ian Thurston): A full TheDraw screen saved as a BINARY file (.BIN) has the same format as the Clipper compiler uses to "SAVE SCREEN TO ". For both Clipper and TheDraw, a full text screen save consists of 2000 "words" (or 4000 bytes). Each word represents the character and attribute of a single screen location. Importing Full-Screen BINARY files: We can easily read any file less than 64k bytes into a Clipper memory variable with the "MEMOREAD" function. Combining the MEMOREAD and RESTORE SCREEN command as follows yields: RESTORE SCREEN FROM MEMOREAD("FULL.BIN") Importing Partial-Screen BINARY files: Once again, a partial/block TheDraw screen saved to a BINARY file (using the ALT-B,Save command) has the same format as Clipper's corresponding command: "=SAVESCREEN(top,left,bottom,right)" For example, assume TheDraw was used to prepare a screen. It was then blocked using ALT-B, with the upper left corner at row 10, column 10, while the lower right corner was at row 20, column 70. The Save option was selecting using the Binary option, and saved to the file "PARTIAL.BIN" Again, the TheDraw Binary file is read into a Clipper memory variable using the "MEMOREAD" function, which itself is used as the argument for the partial screen restore function RESTSCREEN (t,l,b,r,): RESTSCREEN (10,10,20,70,MEMOREAD("PARTIAL.BIN")) Note: As is usual with this sort of function, a block can be restored at a different screen location ... but the width and height must remain the same, else the display will look very ugly indeed. Also correct programming practice would have us check for file existence and length before trying these techniques. You may choose to wrap the functions inside a parameter checking shell. Combining Multiple BINARY (.BIN) Files: If quite a few Binary files will be stored on disk and incorporated into an application, why not combine them into one Clipper database to simplify things? The process for accomplishing this is described below: a. Create a database for .BIN files using the following structure: Structure for database: BIN.DBF Field Field_Name Type Width Dec 1 BIN_NAME Character 8 2 BIN_TOP Numeric 2 3 BIN_LEFT Numeric 2 4 BIN_BOTTOM Numeric 2 5 BIN_RIGHT Numeric 2 6 BIN_SCREEN Memo 10 b. Using the MEMOREAD function, import the BIN files as character variables, then store them in memo field BIN_SCREEN using the REPLACE command. Next, save the screen display coordinates into BIN_TOP, BIN_LEFT, BIN_BOTTOM, and BIN_RIGHT (for a full screen, those coordinates are 0,0,24, and 79). Finally, store a meaningful name for the screen in BIN_NAME (ie: "MAINMENU" for a main menu display). c. Index the file on BIN_NAME. ---- Now to use this file, we need the following function: ******** FUNCTION showbins ******** PARAMETERS screename PRIVATE tempselect tempselect=SELECT() && Keep track of where we were working IF SELECT("BIN") = 0 && Check to see if BIN has been opened SELECT 0 && If not, find a blank work area, USE bin INDEX bin_name && and then open up BIN for use ENDIF SELECT bin && Go to the BIN area SEEK screename && Look for the specified screen IF FOUND() && and show it if it exists RESTSCREEN (bin_top,bin_left,bin_bottom,bin_right,bin_screen) ENDIF SELECT (tempselect) && return to the original work area RETURN .T. Example Usage: SHOWBINS("MAINMENU") PROGRAMMING IN CLIPPER (courtesy of Larry Stewart): The Clipper compiler uses the same format as TheDraw's BINARY save for it's "SAVE SCREEN to memvar" and SAVESCREEN() functions. The code example that follows shows how to retrieve a .BIN file and display it in your compiled EXE program. FUNCTION SHOW_BIN * SYNTAX: SHOWBIN( [, , , , ] ) * PURPOSE: Display a full or partial screen from a .BIN file * ARGUMENTS: contains the name of the .BIN file from TheDraw * If through are not present, the routine * assumes a full screen display will be restored. * is the top row for a partial screen * is the left column for the partial screen * is the bottom row for the partial screen * is the right column for the partial screen PARAMETER binfile,t,l,b,r PRIVATE m_buffer,m_handle,m_bytes,m_size IF ! ("." $ binfile) && Does file have an extension? binfile = binfile+".BIN" && No, default to .BIN ENDIF IF ! FILE(binfile) && Does file exist on disk? RETURN .F. && No, return FAIL value. ENDIF IF PCOUNT() = 1 && Any border dimensions passed? m_buffer = SPACE(4000) && If not, assume full screen. m_handle = FOPEN(binfile,0) m_bytes = FREAD(m_handle,@m_buffer,4000) FCLOSE(m_handle) IF m_bytes = 4000 RESTORE SCREEN FROM m_buffer RETURN .T. ELSE RETURN .F. && Error if .BIN file did not ENDIF && contain 4000 bytes. ENDIF IF PCOUNT() != 5 && Check for correct number of RETURN .F. && parameters. ENDIF m_size = 2*((r-l+1)*(b-t+1)) && Compute number of bytes in m_buffer = SPACE(m_size) && box. Allocate space for it. m_handle = FOPEN(binfile,0) m_bytes = FREAD(m_handle,@m_buffer,m_size) FCLOSE (m_handle) IF m_bytes = m_size RESTSCREEN (t,l,b,r,m_buffer) RETURN .T. ELSE RETURN .F. && Error if file not big enough. ENDIF Please note: When you save a box (binary block save) with TheDraw, the screen position and dimensions are not recorded in the .BIN file. The box may be restored to your screen at any position you choose; however, the dimensions of the box -cannot- be changed. If you try, the box will appear distorted or the above routine will generate an error. Examples: SHOWBIN ("EXAMPLE1") Displays the full screen image in the file EXAMPLE1. SHOWBIN ("EXAMPLE2",10,20,20,60) Displays the 40 by 10 block in EXAMPLE2 at screen position (20,10).