Copyright (1997-2013) EDMGROUP Pty Ltd - EZY Prolog Reference

main page

Dbase III reading sample

EZY Prolog installation has sample program, which demonstrates how to read Dbase III files directly. This application has GUI declarations and associated code. Simply press button, select Dbase III file and EZY Prolog will fill in table with data from database.

/*

 EZY PROLOG. Copyright (C) 2002 EDMGROUP (Australia)

http://www.ezy-software.com

*/

predicates

determ prolog_main

button_db3_handler: EHANDLER

determ grid_db3_initialize(INTEGER GRID_OBJECT)

determ fill_grid(INTEGER GRID_OBJECT,INTEGER DB3_OBJECT)

clauses

prolog_main():-

syspath ( EXEPATH , _ ),

format ( DCL_FILE , "%sezy_dbase3.dcl" , EXEPATH ),

ezy_form_open ( DCL_FILE , WINDOW ),

BUTTON_ADDR =[ "db3_panel" , "Open DB3 File" ],

ezy_get_object ( WINDOW , BUTTON_ADDR , BUTTON_OBJECT ),

ezy_object_handler ( BUTTON_OBJECT , button_db3_handler ),

GRID_ADDRESS =[ "db3_panel" , "db3_data" ],

ezy_get_object ( WINDOW , GRID_ADDRESS , GRID_OBJECT ),

grid_db3_initialize( GRID_OBJECT ),

write ( "Welcome to EZY Prolog" ),

nl .

button_db3_handler( _ ,e_control( _ , _ , BUTTON_OBJECT , _ )):-

ezy_object_name ( BUTTON_OBJECT , NAME ),

NAME = "Open DB3 File" ,

dlg_openfilename ( "Open DbaseIII file" , "Db III file" , "*.dbf" , SELECTED_FILE ),

db3_open ( SELECTED_FILE , DB3_OBJECT ),

db3_properties ( DB3_OBJECT , _ , TOTALRECS , FIELD_LIST ),

ezy_get_parent ( BUTTON_OBJECT , "db3_panel" , WINDOW ),

PANEL_ADDR =[ "db3_panel" , "db3_properties" ],

ezy_get_object ( WINDOW , PANEL_ADDR , PANEL_OBJECT ),

TEXT_FLAGS =[ dtext_Expandtabs , dtext_Left ],

format ( TEXT , "This is properties of DB3 file\nFilename %\nTotal records %" , SELECTED_FILE , TOTALRECS ),

CAPTION =vps_text( TEXT , TEXT_FLAGS ),

ezy_frame_caption ( PANEL_OBJECT , CAPTION ),

GRID_ADDRESS =[ "db3_panel" , "db3_data" ],

ezy_get_object ( WINDOW , GRID_ADDRESS , GRID_OBJECT ),

ezy_grid_columns ( GRID_OBJECT , FIELD_LIST ),

fill_grid( GRID_OBJECT , DB3_OBJECT ),

db3_close ( DB3_OBJECT ),

ezy_grid_rows ( GRID_OBJECT , TOTALRECS ),

! .

fill_grid( GRID_OBJECT , DB3_OBJECT ):-

db3_read ( DB3_OBJECT , RECORD_LIST ),

RECORD_LIST =[ ROW |_],

ezy_grid_addrow ( GRID_OBJECT , RECORD_LIST ),

fail .

fill_grid( _ , _ ):-

! .

grid_db3_initialize( GRID_OBJECT ):-

MAXROW = 0 ,

ezy_grid_rows ( GRID_OBJECT , MAXROW ),

COLUMN_LIST =[ "COLUMN1" , "COLUMN2" , "COLUMN3" ],

ezy_grid_columns ( GRID_OBJECT , COLUMN_LIST ),

! .