groupingofrepetitivefunctionsonUserArchivesinonefunction.

上传人:夏** 文档编号:470403634 上传时间:2023-09-19 格式:DOC 页数:9 大小:434.50KB
返回 下载 相关 举报
groupingofrepetitivefunctionsonUserArchivesinonefunction._第1页
第1页 / 共9页
groupingofrepetitivefunctionsonUserArchivesinonefunction._第2页
第2页 / 共9页
groupingofrepetitivefunctionsonUserArchivesinonefunction._第3页
第3页 / 共9页
groupingofrepetitivefunctionsonUserArchivesinonefunction._第4页
第4页 / 共9页
groupingofrepetitivefunctionsonUserArchivesinonefunction._第5页
第5页 / 共9页
点击查看更多>>
资源描述

《groupingofrepetitivefunctionsonUserArchivesinonefunction.》由会员分享,可在线阅读,更多相关《groupingofrepetitivefunctionsonUserArchivesinonefunction.(9页珍藏版)》请在金锄头文库上搜索。

1、Sample program: grouping of repetitive functions on User Archives in one function.QUESTION:How can I reduce the C code with scripts for accessing User Archive? ANSWER:If you program scripts for accessing User Archive, then there are large volumes of code for the administration tasks. This code is th

2、e same for accessing all User Archives. The example here shows an option for grouping the administration tasks together in one function. The script structure looks like this for standard programming methods: 1. Generating the sorting and filtering conditions 2. Setting up a connection to the User Ar

3、chiveuaConnectuaQueryArchiveByNameif error: return 3. Setting the sorting and filtering conditionsuaArchiveSetFilteruaArchiveSetSort 4. Opening the queryuaArchiveOpen 5. Actually working with the queryRead, write, delete, insert and so on. 6. Clearing down the connection to the User ArchiveuaArchive

4、CloseuaReleaseArchiveuaDisconnect If you program everything with fault check in one function, the function becomes too large and unclear.If you take a close look at the list above, you will be able to see that only points 1 and 5 change from case to case.All the other points remain the same no matte

5、r what structure the User Archive has. You can split the above structure into 3 functions. 1. The task-related function takes care of point 1. It generates the filters and sorting conditions. 2. A general function that encapsulates all administration actions. This function applies for ALL User Archi

6、ves. The function receive a callback function as parameter. This callback function is called either for each entry in the query or just once for the entire archive. 3. A callback function, this function process point 5. This division means that you dont have to worry about the administration actions

7、. You program just one function for query generation and one archive-related function, which processes the archive entries. In the following example we use the function uaUtilityEnumRecords. Function description: BOOL uaUtilityEnumRecords( Const char* pszArchiveName ,const char* lpszFilter,const cha

8、r* lpszSort,BOOL ( UserFunc )( UAHARCHIVE* phUA, void* pUserData ),void* pUserData ) Parameters: pszArchiveName: Pointer to a zero-terminated string. The string contains the name of the archive as it appears in the User Archive editor. lpszFilter: Pointer to a zero-terminated string. The string cont

9、ains the filter condition for the archive. The pointer can also be ZERO. lpszSort: Pointer to a zero-terminated string. The string contains the sorting condition for the archive. The pointer can also be ZERO. UserFunc: Name of a callback function. The function is called for each entry if you transfe

10、r a filter. The function is called once for the entire archive if you do not transfer a filter. The function must be of the following type:BOOL ( UserFunc )( UAHARCHIVE* phUA, void* pUserData ). pUserData: Pointer to user data. The pointer is forwarded without modification to the callback function.

11、Return value: The function returns the value TRUE if: no faults have occurred during connection setup and clear-down. the callback function always returns TRUE. Otherwise the value FALSE is returned. Function:The uaUtilityEnumRecords function carries out the following steps: 1. Sets up connection to

12、 the User Archive. 2. Sets the filter and sorting conditions if they are transferred. 3. Opens the query. 4. If no filter has been set, the function calls the callback function with the handle to the archive.If the filter exists, the callback function is called in a loop for each entry in the query

13、with the handle to an entry. As soon as the CB function returns the value FALSE, the loop is terminated. The function uaUtilityEnumRecords then returns the FALSE. 5. After the callback function has been processed, the connection to the archive is set up. You see the code of the function in the follo

14、wing PDF document:uaUtilityEnumRecords_1.pdf ( 7 KB ) 代码:#include apdefap.hBOOL uaUtilityEnumRecords( const char* pszArchiveName , const char* lpszFilter, const char* lpszSort,BOOL ( UserFunc ) ( UAHARCHIVE* phUA, void* pUserData ),void* pUserData )/*Function create a Query for a User Archive specif

15、ied by Filter and sort condition. Function calls for eachRecord in Query User function if Filter specified. If not filter spezified function calls user function only onetime.ParameterhArchive: Handle to a User ArchivelpszFilter: Pointer to Zerro Terminated string with Filter for User Archive. If Poi

16、nter isnt NULL functionmake new Query from Archive, and calls for EACH record User Function !If Pointer is NULL: Function create conection to User Archive whithout filter.In this Case user function is called only ONE TIME !lpszSort: pointer to zeroterminated string with sort conditionlpFunc: Pointer to Us

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 资格认证/考试 > 自考

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号