用户访问代码优化方法.pdfVIP

  • 0
  • 0
  • 约2.33万字
  • 约 18页
  • 2026-01-28 发布于北京
  • 举报

示例程序:将用户中重复的功能组合到一个函数中。

问题:

如何减少用户的C代码?

如果您编写用于用户的,则会有很多代码用于管理任务。这些代码在所

有用户时都是相同的。这里的示例展示了将管理任务组合到一个函数中的方法。

使用编程方法的结构如下所示:

1.生成排序和过滤条件2.建立与用户的连接

uaConnectuaQueryArchiveByName如果出错:

返回3.设置排序和过滤条件uaArchiveSetFilter

uaArchiveSetSort4.打开查询uaArchiveOpen

5.实际处理查询、写入、删除、等。6.清

理与用户的连接uaArchiveClose

uaReleaseArchiveuaDisconnect

如果你在一个函数中编程时都进行错误检查,该函数会变得太大且不清晰。

仔细查看上面的列表,你会发现只有第1点和第5点会根据情况变化。

其他所有点无论用户的结构如何都会保持不变。

你可以将上述结构拆分为3个函数。

1.与任务相关的功能负责第1点。它生成过滤器和排序条件。2.一个封装所有

管理操作的通用功能。此功能适用于所有用户。该功能接收一个回调函数

作为参数。此回调函数要么对查询中的每个条目进行调用,要么仅对整个

调用一次。3.一个回调函数,该函数处理第5点。

Sampleprogram:groupingofrepetitivefunctionsonUserArchivesinonefunction.

QUESTION:

HowcanIreducetheCcodewithscriptsforaccessingUserArchive?

ANSWER:

IfyouprogramscriptsforaccessingUserArchive,thentherearelargevolumesofcodeforthe

administrationtasks.ThiscodeisthesameforaccessingallUserArchives.Theexamplehere

showsanoptionforgroupingtheadministrationtaskstogetherinonefunction.

Thescriptstructurelookslikethisforstandardprogrammingmethods:

1.Generatingthesortingandfilteringconditions

2.SettingupaconnectiontotheUserArchive

uaConnect

uaQueryArchiveByName

iferror:return

3.Settingthesortingandfilteringconditions

uaArchiveSetFilter

uaArchiveSetSort

4.Openingthequery

uaArchiveOpen

5.Actuallyworkingwiththequery

Read,write,delete,insertandsoon.

6.ClearingdowntheconnectiontotheUserArchive

uaArchiveClose

uaReleaseArchive

uaDisconnect

Ifyouprog

您可能关注的文档

文档评论(0)

1亿VIP精品文档

相关文档