The translation is from Google
I present to https://you.com/ that through >_ Code or in the Chat of its menu, you can generate
HMG code. by indicating a small indication for you to write code, example:
Mustafa =>
create a code in HMG with main window type DEFINE WINDOW Form_1 ,
with a query GRID and a dbf database
fields "Name" and "Age" if the database does not exist, you have to create it
also create an "exit" button with your code
You.com=>
Here I provide you with an example of HMG code that meets the requirements you request.
The code creates a main window with a query GRID and a dbf with
"Name" and "Age" fields. It also includes an "Exit" button with its corresponding code:
and I create this code
Code: Select all
#include "hmg.ch"
FUNCTION Main()
// Crear base de datos dbf
IF ( ! File( "datos.dbf" ) )
USE datos NEW
datos->( dbStruct( { "Name C(30)", "Age N(3)" } ) )
ENDIF
// Crear ventana principal
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE "Consulta de Datos" ;
MAIN
// Crear GRID de consulta
DEFINE GRID Grid_1
ROW 40
COL 40
WIDTH 550
HEIGHT 300
HEADERS { "Nombre", "Edad" }
WIDTHS { 400, 100 }
FIELDS { "Name", "Age" }
FONT { "Tahoma",10,0 }
VALUE {||}
PICTURES {||}
ON ROW DOUBLECLICK SELECT (*Grid_1).Value
END GRID
// Crear botón "Exit" con su código correspondiente
DEFINE BUTTON Button_1
ROW 350
COL 270
CAPTION "Exit"
WIDTH 100
ACTION Salir
END BUTTON
END WINDOW
ACTIVATE WINDOW Form_1
RETURN NIL
// Código del botón "Exit"
PROCEDURE Salir()
CLOSE DATABASES
QUIT
RETURN
Keep in mind that this is just an example and you will need to adapt it to your specific needs.
There may also be bugs or special cases that you need to handle.
Mustafa-> in the GRID ROWSOURCE "Data" is missing
you.com=>
You are right, by adding the line ROWSOURCE "Data" when defining the GRID, the GRID is bound
with the database and displays the data from the database in window [1].
Here I show you what the GRID definition should look like:
Code: Select all
// Crear GRID de consulta
DEFINE GRID Grid_1
ROW 40
COL 40
WIDTH 550
HEIGHT 300
HEADERS { "Nombre", "Edad" }
WIDTHS { 400, 100 }
FIELDS { "Name", "Age" }
FONT { "Tahoma",10,0 }
VALUE {||}
PICTURES {||}
ROWSOURCE "Datos"
ON ROW DOUBLECLICK SELECT (*Grid_1).Value
END GRID
and it will display the records in the window.
I hope this resolves your query. If you have any other questions, don't hesitate to ask.
I only had to correct a little the code provided by You.com and it's OK!
Mustafa=> Fixed Code
Code: Select all
#include "hmg.ch"
FUNCTION Main()
// Crear base de datos dbf
IF ( ! File( "datos.dbf" ) )
Crea_Base()
ELSE
USE Datos NEW
Datos->(dbStruct( { "Name C(30)", "Age N(3)" } ))
ENDIF
// Crear ventana principal
DEFINE WINDOW Form_1 ;
AT 0,0 ;
WIDTH 640 HEIGHT 480 ;
TITLE "Consulta de Datos" ;
MAIN
DEFINE GRID Grid_1
ROW 40
COL 40
WIDTH 550
HEIGHT 300
HEADERS { "Name", "Age" }
WIDTHS { 400, 100 }
ROWSOURCE "Datos"
COLUMNFIELDS { "Name", "Age" }
FONTNAME { "Tahoma",10,0 }
END GRID
// Crear botón "Exit" con su código correspondiente
DEFINE BUTTON Button_1
ROW 350
COL 270
CAPTION "Exit"
WIDTH 100
ACTION Salir()
END BUTTON
END WINDOW
CENTER WINDOW Form_1
ACTIVATE WINDOW Form_1
RETURN NIL
// Código del botón "Exit"
PROCEDURE Salir()
CLOSE DATABASES
QUIT
RETURN NIL
*-----------------------------------*
FUNCTION Crea_Base()
*-----------------------------------*
LOCAL aStruct := { ;
{ "NAME" , "C", 30, 0 }, ;
{ "AGE" , "N", 03, 0 } ;
}
DbCreate( "Datos", aStruct, .T. )
USE datos NEW
DbAppend()
REPLACE NAME WITH "Peter"
REPLACE AGE WITH 20
DbAppend()
REPLACE NAME WITH "Carolyn"
REPLACE AGE WITH 15
dbcloseall()
USE datos NEW
Return
Saludos , Regards , Salam
Mustafa