PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK
  • Example 1: Creating an alias to use the data found in an archived file
  • Example 2: Copying data between two files with the same structure
Example 1: Creating an alias to use the data found in an archived file
WINDEVWindowsJavaUser code (UMC)HFSQLStored procedures The following example is used to handle the data found in the Orders2013 file (order file for the year 2013) archived in the D:\SalesMgt\Archive2013 directory. This file corresponds to the description of the ORDERS file found in the analysis.
// Create an alias for the ORDERS file
// (Syntax available from version 19)
Orders2013 is Data Source <description=Orders>
IF HAlias(Order, Order2013) = True THEN
// ORDERS2013 can now be used in the processes
// It behaves the same way as
// the ORDERS file described in the analysis.
// Modify the directory
HChangeDir(Orders2013, "D:\SalesMgt\Archive2013")
// Modify the name
HChangeName(Orders2013, "Orders")
HOpen(Orders2013)
...
// Processes on the Orders2013 file
...
END
// Cancel the alias
HCancelAlias(Orders)
Example 2: Copying data between two files with the same structure
WINDEVWindowsJavaUser code (UMC) This example is used to copy the records found in TempCustomer.Fic to Customer.Fic. The TemCustomer file in this example is an existing file containing the customers that will be copied into the Customer file.
// Declare the alias
TempCustomer is Data Source <description=Customer>
// (Syntax available from version 19)
// Create the alias
IF HAlias(Customer, TempCustomer) = True THEN
// If TempCustomer.FIC is found in another directory,
// you must add:
// HChangeDir(TempCustomer,"C:\MyDir\AliasDir")
// Physically create (or open) the TempCustomer.Fic file
HCreationIfNotFound(TempCustomer)
  // To filter the copied elements,
// add an HFilter function here
...
  // Browse the records found in TempCustomer.Fic
  HReadFirst(TempCustomer, "CustomerName")
  WHILE NOT HOut(TempCustomer)
// Copies the record in memory
// from TempCustomer.Fic file to Customer.Fic file
 IF HCopyRecord(Customer, TempCustomer) THEN
 // Add into Customer.Fic
 // Automatic file identifier recalculated if it exists
 HAdd(Customer)
 // Addition OK? (check the integrity and duplicates)
 IF HErrorDuplicates() = True OR ...
HErrorIntegrity() = True THEN
  IF YesNo("Duplicates error " + ...
"or integrity error "+ ...
"while adding " + ...
Customer.CustomerName + CR + ...
"Continue?") = False THEN
// Stop processing the copy of records
// Exit from the WHILE loop
BREAK
  END
 END
  ELSE
// Error on HCopyRec function
// Display an error message
Error("Unable to copy the records")
// Interrupt the process
// Exit from the WHILE loop
BREAK
  END
  HReadNext(TempCustomer, "CustomerName")
END
ELSE
// Error on HAlias function
// Display a message for the error
  Error("Error details" + HErrorInfo())
END
Minimum version required
  • Version 9
This page is also available for…
Comments
EXAMPLE
// Sincronização de dados

TempCliente is Data Source

HAlias(Cliente, TempCliente)

HCreationIfNotFound(TempCliente)



FOR EACH Cliente WHERE Enviado = 0

TempCliente.A = Cliente.A

TempCliente.B = Cliente.B

HAdd(TempCliente)

END



HCloseConnection(ConnectionLOCAL)

HOpenConnection(ConnectionSERVER)

HchangeConnection(*,ConnectionSERVER)



FOR ALL TempCliente

IF HCopyRecord(Customer, TempCustomer) THEN

Hadd(Cliente)

END

END



HCancelAlias(TempCustomer)

fDelete(Diretorio,"TempCustomer.fic")

Info("Transferência realizada com sucesso!")

//Pra quem gosta das coisas mastigadas (FABRICIO ALMEIDA)
BOLLER
06 Jan. 2018