Dynamic data window creation principle and implementation

zhaozj2021-02-11  228

Creating dynamic data window principle and implementation of: Flow square Home: http: //liulee.myrice.com

In practical applications, it is often necessary to dynamically create data windows according to user needs, and the general method is like this.

Add a data window control in a Window, such as dw_new, but the data window does not have Data Object, (blank)

You can use the following syntax to create:

DW_NEW.CREATE (LS_SYNTAX, LS_ERROR) // Create a syntax, error message

LS_SYNTAX can be formed by the following three methods:

First, the dynamic is created by SQL syntax:

// Connect to the example database of the PB

String ls_sql, ls_syntax, ls_error

LS_SYNTAX = 'SELECT * from Department'

LS_SYNTAX = SQLCA.SYNTAXFROMSQL (ls_sql, 'style (type = grid)', LS_ERROR)

IF LEN (LS_ERROR)> 0 THEN

MessageBox ('Error', 'SyntaxFromsql Error: ~ R' LS_ERROR)

Else

DW_NEW.CREATE (Ls_Syntax, Ls_ERROR)

IF LEN (LS_ERROR)> 0 THEN

MessageBox ("Error", "Create Have these Errors: ~ r" ls_error)

Else

DW_New.SetTransObject (SQLCA)

DW_New.Retrieve ()

END IF

END IF

Second, create the Syntax of another data window to create

String ls_syntax, ls_error

Ls_syntax = dw_test.describe ('DataWindow.Syntax')

DW_NEW.CREATE (Ls_Syntax, Ls_ERROR)

IF ls_error <> '' THEN

MessageBox ('Create Error', LS_ERROR)

Else

DW_New.SetTransObject (SQLCA)

DW_New.Retrieve ()

END IF

Third, read the PSR file to create

Sample

String ls_syntax, ls_error, ls_ret

LS_RET = char (13) char (10) // Enter key

INT Li_Filenum

Long li_length

Li_filenum = fileopen ("efef.psr", streammode !, read !, shared !, replace!)

/ / The following is the code of PB5

IF li_filenum> 0 THEN

Fileseek (li_filenum, 158, frombeginning!)

LI_LENGTH = FileRead (li_filenum, ls_syntax)

END IF

FILECLOSE (li_filenum)

IF li_length = 0 THEN RETURN

Ls_syntax = "Release 5;" LS_RET LS_SYNTAX

/ / Take the data section in LS_SYNTAX, 5.0 "sparse (names =" dept_name?) As a reference location

//6.0 with HTML (as a reference position)

Long Pos1, POS2

POS1 = POS (ls_syntax, 'spival (names = ", 1) POS2 = POS (ls_syntax,'", POS1 16)

LS_SYNTAX = Left (Ls_SYNTAX, POS1) MID (Ls_SYNTAX, POS1 1, POS2 - POS1 1)

DW_NEW.CREATE (Ls_Syntax, Ls_ERROR)

IF ls_error <> '' THEN

MessageBox ('Create Error', LS_ERROR)

Else

DW_New.SetTransObject (SQLCA)

DW_New.Retrieve ()

END IF

// PB6, PB7 code can be written by PB5 itself, but the file header and data window end tag are different.

转载请注明原文地址:https://www.9cbs.com/read-3752.html

New Post(0)