Browse vs. Grid

General Help regarding HMG, Compilation, Linking, Samples

Moderator: Rathinagiri

mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Browse vs. Grid

Post by mrduck »

nguyenchiduc wrote: I do not understand "virtual grids" what is but I have a test for my database. And the result is very good for any file .dbf with any capacity.
Hi,
when someone posts some code I'm always happy because I can learn how other people solve problems.
And you did a smart thing... you copy a subset of the master (probably big) file into a temporary file so that the grid actually moves inside this really small dbf....

very clever indeed !

Browsing your code I found a little code snippet that can be optimized...
This code:

Code: Select all

    FOR i := 1 to k
      command := "temp->" + FIELDNAME(i) + ":= " + "data->" + FIELDNAME(i) 
      &command         
    NEXT
can be replaced with: (not tested, but should work)

Code: Select all

    FOR i := 1 to k
      temp->(fieldput(i,data->(fieldget(i))))
    NEXT
In this way you don't use macro to compile and execute the assignment...

recently fieldput and fieldget were extended to accept the fieldname as first parameter, instead of a numerical field position
fieldput( fieldpos("field"), "value" ) can also be written as fieldput( "field", "value" )

I think that the loop can be a bit optimized too and moved to a function but it depends on coding style.

Francesco
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: Browse vs. Grid

Post by nguyenchiduc »

mrduck wrote: recently fieldput and fieldget were extended to accept the fieldname as first parameter, instead of a numerical field position
fieldput( fieldpos("field"), "value" ) can also be written as fieldput( "field", "value" )

I think that the loop can be a bit optimized too and moved to a function but it depends on coding style.

Francesco
Thank you very much
Knowledge of the Harbour (CA-Clipper) I learned from this:

http://www.itlnet.net/programming/progr ... /menu.html

because of historical problems in Vietnam that people only know the FoxPro for DOS or VFP not know Xbase what was, until Vietnam connection Internet in 1999. About 5-7 years, the Internet began to thrive in the Vietnam

If you see my code shaky, not professional, please help my bad habit.

I learned a lot not only about HMG from www.hmgforum.com

Again thank you
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Browse vs. Grid

Post by sudip »

Hello Brother Esgici,

As far I remember I saw the problem, from one your examples. It's regarding some cell or item problem when we are using grid with table (I mean virtual grid). (But right now, I can't find that specific example in my new computer :( )

Moreover, with ordinary grid, we can use CellNavigation property both .t. or .f. But with virtual grid we can use CellNavigation property .t. only.

When CellNavigation property is .f., a grid can be used as a incremental searched listbox also!!! :D But, I can't use this with VirtualGrid with table.

So, I am always using NORMAL grid. There also another reason behind this. Most of my HMG projects are using SQLite as DBMS, where I retrieve data from tables into local array and store them directly into grid.

This is my personal views. As you have much better knowledge on HMG than me, you can tell me whether I am right or wrong :)

Thank you very much :)
With best regards,
Sudip
User avatar
esgici
Posts: 4543
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Contact:

Re: Browse vs. Grid

Post by esgici »

Hi Sudip,

Thanks for explanations.

Regards

--

Esgici
Viva INTERNATIONAL HMG :D
mrduck
Posts: 497
Joined: Fri Sep 10, 2010 5:22 pm

Re: Browse vs. Grid

Post by mrduck »

nguyenchiduc wrote: If you see my code shaky, not professional, please help my bad habit.
I'm not a professional but I'd change your code as you can see here.

I did move the code that is repeated in a procedure. The PUBLIC vars moved as file-wide static (public have the drawback that will stay defined in upper level code. I moved k in the procedure but it can be moved back as file-wide static in order to not waste cpu on fieldcount().
In the procedure I prefer to have in a loop only one check for exit code so I moved the check for 20th rows near the eof() check.

I then changed the code to call the procedure.

I didn't test the code since I don't have hmg3 on my system, but I believe it should work without problems. I don't understand if it will handle page-up/down keys... and what about vertical scrollbars ?

Francesco

Code: Select all


PUBLIC start


// cpy copies rows from db DATA to db TEMP up to 20 records or EOF
// starting from record number stored in start static file-wide variable 
// On enter sets correct workarea
// On enter workarea is DATA

Static Procedure cpy( )
LOCAL j := 0
LOCAL k
LOCAL i

select temp
goto 3

select data
goto start

k := FCOUNT()

DO WHILE .NOT. EOF() .AND. j <= 20

    SELECT temp

    FOR i := 1 to k
      temp->(fieldput(i,data->(fieldget(i))))
    NEXT

    temp->( DBCOMMIT() )
    temp->( DBSKIP() )

    select data
    data->( DBSKIP() )

    j++

ENDDO
RETURN


Function Main
LOCAL header := {}, field := {}, width := {}, control := {}, i := 0, k

start := 1

USE P:\hd\dm1.dbf alias data SHARED READONLY NEW via "DBFCDX"
/* P:\hd\dm1.dbf in Novell Intranet not in my PC */

COPY STRUCTURE TO temp
USE temp alias temp new via "DBFCDX"
FOR i := 1 to 22
    append blank
NEXT
goto 3

/* Display on the screen 20 rows. 2 rows to empty, used for calculations when changing position records */

k := FCOUNT()
FOR i := 1 to k 
      AADD(header , FIELDNAME(i))
      AADD(field , FIELDNAME(i))
      AADD(width , DBFIELDINFO(DBS_LEN,i)*11)
   
      DO CASE
      CASE DBFIELDINFO(DBS_TYPE,i) == "C"
          AADD(control,{"TEXTBOX","CHARACTER"})
      CASE DBFIELDINFO(DBS_TYPE,i) == "N"
          AADD(control,{"TEXTBOX","NUMERIC"})
      CASE DBFIELDINFO(DBS_TYPE,i) == "D"
          AADD(control,{"TEXTBOX","DATE"})
      ENDCASE
NEXT

/* declare the parameters to display the temp.dbf file with GRID */
cpy( 1 )

DEFINE WINDOW Main AT 0,0 WIDTH 800 HEIGHT 600 MAIN

     @ 130,0 GRID data_view WIDTH 790 HEIGHT 430 ROWSOURCE 'temp' ;
     HEADERS header WIDTHS width COLUMNCONTROLS control COLUMNFIELDS field  ON CHANGE change_display()
      ON KEY ESCAPE ACTION quit()
      ON KEY HOME ACTION goto_top()
      ON KEY END ACTION goto_bottom()             
END WINDOW

  Main.data_view.Setfocus   
  CENTER WINDOW Main
  ACTIVATE WINDOW Main
   
RETURN

FUNCTION goto_top()
  start := 1
  cpy( ) 
           
  Main.data_view.Recno := 3
 
RETURN



FUNCTION goto_bottom()
 
  select data 
  start := data->( reccount() )
  cpy( )

  start := reccount()         
  Main.data_view.Recno := 22
 
RETURN


FUNCTION  change_display()
  LOCAL location 

  location := Main.data_view.recno

  /* top position of GIRD (No. 2)  */
 
  IF location == 2
        /* check the top position in the data file (dm2.dbf) */
       
    IF start > 1
     
          start := start - 1
          cpy(  )
     
          temp->( DBCOMMIT() ) // why this command ?
                               // it is already done in cpy procedure....
    ENDIF
       
    Main.data_view.Recno := 4
  ENDIF         
 
  /*bottom of the grid position (No. 20)*/
 
  IF location == 20

     /*check the bottom of the file data (dm2.dbf)*/
     
     IF start < data->( reccount() )
     
        start := start + 1
        cpy(  )
     
        temp->( DBCOMMIT() )   // ??????
     
        Main.data_view.Recno :=  20
   
     ENDIF       
  ENDIF 

RETURN NIL
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: Browse vs. Grid

Post by nguyenchiduc »

BROWSE command of VFP is very fast, when opening large files, millions of records. 2G is the maximum in VFP

SELECT ... FROM .. WHERE command can display many records on the screen.

Similar to SET FILTER TO

From time to start before the quit command is executed. There are many temp files are created in VFP, depending on the command was created.

But the command "LOCATE", "SEEK", "DO WHILE" is similar to HMG (Harbour) when handling large files.

VFP only improve the display on the screen while the command is still basically XBase. History of VFP is still based on XBase.

===================

So I believed, HMG may be this way.
User avatar
nguyenchiduc
Posts: 78
Joined: Sat Nov 13, 2010 7:27 am

Re: Browse vs. Grid

Post by nguyenchiduc »

mrduck wrote:
nguyenchiduc wrote: If you see my code shaky, not professional, please help my bad habit.
I didn't test the code since I don't have hmg3 on my system, but I believe it should work without problems. I don't understand if it will handle page-up/down keys... and what about vertical scrollbars ?

Francesco
Thank you for sharing!
I also think of this idea, but I have not had time to implement. Currently I still use VFP to view the file.
Because at the same time I have to get information of several files, so I have to save display space. The fact that the number 10 not 20.

I illustrate briefly:

When the "pointer" to run to the top of the GRID: START: = START - 1
When the "pointer" to run to the end of the GRID: START = START + 1
With the PAGE UP: START: = START - 20
With the PAGE DOWN: START: = START + 20.
With HOME: START = 1
with END: START = RECCOUNT() (of data not temp.dbf)

Add scrollbar is complete, calculate the ratio of the number of records when sliding the scroll bar. Right now I do not

START is the real location of the records on file to view
temp.dbf only to display: you can generate random
User avatar
sudip
Posts: 1456
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India

Re: Browse vs. Grid

Post by sudip »

Yes, as per VFP 6 is concerned (which is the last version I worked), embedded SQL commands are FASTER!

You may try with SQLite and MySql. For QUERY SubSet, SQL databases are faster than record based databases like DBFCDX. Moreover, infamous database corruption problem of VFP's table is very little with SQL databases (in my small experience, I didn't encounter any such problem with SQL databases with HMG).

Regarding temporary tables (or what we called "cursor" in VFP), you can use also with HMG (or Harbour), for example:

Code: Select all

   adbf := {}
   aadd(adbf, {'invdt', 'd', 8, 0})
   aadd(adbf, {'vatonmrp', 'l', 1, 0})
   aadd(adbf, {'mrpamt', 'n', 12, 2})
   aadd(adbf, {'amt', 'n', 12, 2})
   aadd(adbf, {'less', 'n', 12, 2})
   aadd(adbf, {'vatrate', 'n', 5, 2})               
   dbcreate('curPurdtl', adbf, 'SQLMIX', .t., 'curPurdtl')
I found HMG is very easy to learn for the VFP developers, because Roberto Lopez himself also used VFP! :)
With best regards,
Sudip
Post Reply