VFP 愛用者社區 首頁 VFP 愛用者社區
本討論區為 Visual Foxpro 愛用者經驗交流的地方, 請多多利用"搜尋"的功能, 先查看看有無前例可循, 如果還有不懂的再發問. 部份主題有附加檔案, 須先註冊成為社區居民才可以下載.
 
 常見問題常見問題   搜尋搜尋   會員列表會員列表   會員群組會員群組   會員註冊會員註冊 
 個人資料個人資料   登入檢查您的私人訊息登入檢查您的私人訊息   登入登入

Building a Data Dictionary(轉貼)

 
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區
上一篇主題 :: 下一篇主題  
發表人 內容
Ruey



註冊時間: 2003-03-12
文章: 1698
來自: tunglo

第 1 樓

發表發表於: 星期日 一月 25, 2004 9:44 am    文章主題: Building a Data Dictionary(轉貼) 引言回覆

Building a Data Dictionary
How do you create a cursor in the Load event? You could hard-code the creation of each cursor, but there’s a better way: You can use a Data Dictionary that contains the information needed to build the cursor, then call the CreateCursor() function described below.

The Data Dictionary table looks like this:

Listing 7 - The DataDict table for creating cursors as needed

DATADICT.DBF:
CursorName Character(30),
FieldName Character(30),
FieldType Character(10),
FieldLen Numeric ( 3),
Decimals Numeric ( 1)
I’ve written a little program to make it easy for you to add your existing DBFs to the Data Dictionary table:

Listing 8 - Program to add a DBF’s structure to the DataDict table

Program-ID... ..:Add2DD.PRG
Purpose.........: Adds a table’s fields to the DataDict table
IF EMPTY ( ALIAS() )
MessageBox ( [No table is open in the current work area], 64 )
RETURN
ENDIF
NewAlias = ALIAS()
=AFIELDS( FA )
FOR I = 1 TO ALEN ( FA )
INSERT INTO DataDict VALUES ( ;
NewAlias, FA(I,1), FA(I,2), FA(I,3), FA(I,4) )
ENDFOR
The CreateCursor function follows. Note that the Create Cursor command requires an array with 16 columns, since that’s the number of columns in arrays created by AFIELDS() function:

Listing 9 - Program to create a local cursor using a structure from DataDict

* Program-ID...: CreateCursor.PRG
* Purpose......: Creates a cursor from a tablename
PARAMETERS CurName
SELECT FieldName, FieldType, FieldLen, Decimals FROM DataDict ;
WHERE ALLTRIM(UPPER(CursorName)) == ALLTRIM(UPPER(CurName))INTO ARRAY CurDef
IF TYPE ( [CurDef(1)] ) = [U]
Msg = [Programmer error:] + CHR(13) ;
+ CurName
+ [ fields not found in data dictionary]
MESSAGEBOX( Msg, 64, _VFP.Caption )
ENDIF

DIMENSION CA ( ALEN(CurDef,1), 16 )
STORE [] TO CA
FOR I = 1 TO ALEN ( CA,1)
CA(I,1) = ALLTRIM(CurDef(I,1))
CA(I,2) = ALLTRIM(CurDef(I,2))
CA(I,3) = CurDef(I,3)
CA(I,4) = CurDef(I,4 )
CA(I,5) = .F.
CA(I,6) = .F.
ENDFOR
CREATE Cursor &CurName FROM ARRAY CA
USE EXCL
RELEASE CA, CurDef
IF USED ( [DataDict] )
USE IN DataDict
ENDIF

_________________
#############################
快樂媽咪系列幸福宅配,喝十全雞湯~原來幸福那麼簡單!!

學會VFP使用者社區的搜尋,Code才會更有趣~
#############################
回頂端
檢視會員個人資料 發送私人訊息
從之前的文章開始顯示:   
發表新主題   回覆主題    VFP 愛用者社區 首頁 -> VFP 討論區 所有的時間均為 台北時間 (GMT + 8 小時)
1頁(共1頁)

 
前往:  
無法 在這個版面發表文章
無法 在這個版面回覆文章
無法 在這個版面編輯文章
無法 在這個版面刪除文章
無法 在這個版面進行投票
無法 在這個版面附加檔案
無法 在這個版面下載檔案


Powered by phpBB © 2001, 2005 phpBB Group
正體中文語系由 phpbb-tw 維護製作