PalmOS开发教程-5.1
第五章 数据库
Palm OS的所有内容在其存储器中都表现为数据库形式,下面我们就开始学习创建和使用数据库。我们将继续编写Contacts程序,把它写入一个数据库。
删除工作
为准备向Contacts添加一个数据库,首先应删除以前的示范语句。
备份Contacts程序
首先应备份当前的Contacts程序。我将它命名为Contacts CH.4。
步骤如下:
1. 运行Windows浏览器;
2. 找到并选中Contacts工程文件夹;
3. 按下CTRL-C复制文件夹;
4. 单击你想备份到的文件夹;
5. 按下CTRL-V将Contacts工程文件夹粘贴;
6. 单击Contacts的名字,将其改名为Contact CH.4。
从资源文件将原来的资源删除
把我们不再用到的一些资源从工程中删除。步骤如下:
1. 打开资源构造器;
2. 打开Contacts工程src文件夹中的Contacts.rsrc文件;
3. 选中FieldInit字符串资源,按Delect删除;
4. 关闭并保存Contacts.rsrc。
删除代码
在删掉资源后,我们要删除和重新组织代码使程序正常运行。
步骤如下:
1. 运行Code Warrior集成开发环境;
2. 从Contacts工程文件夹打开Contacts.mcp;
3. 从PilotMain()的刚开始处中删除下列代码:
// CH.3 Our field memory handle
static Handle htext; // CH.3 Handle to the text in our edit field
#define HTEXT_SIZE 81 // CH.3 Size of our edit field
4. 从PilotMain()接近顶部的地方删除下列代码:
// CH.3 Get the initialization string resource handle
hsrc = DmGetResource( strRsc, FieldInitString );
// CH.3 Lock the resource, get the pointer
psrc = MemHandleLock( hsrc );
// CH.3 Allocate our field chunk
htext = MemHandleNew( HTEXT_SIZE );
if( htext == NULL )
return( 0 );
// CH.3 Lock the memory, get the pointer
ptext = MemHandleLock( htext );
// CH.3 Initialize it
StrCopy( ptext, psrc );
// CH.3 Unlock the field's memory
MemHandleUnlock( htext );
// CH.3 Unlock the resource's memory
MemHandleUnlock( hsrc );
// CH.3 Release the string resource
DmReleaseResource( hsrc );
5. 从contactDetailEventHandler()中将frmOPenEvent事件处理部分删掉下列代码:
// CH.3 Get the index of our field
index = FrmGetObjectIndex( form, ContactDetailFirstNameField );
// CH.3 Get the pointer to our field
field = FrmGetObjectPtr( form, index );
// CH.3 Set the editable text
FldSetTextHandle( field, htext );
// CH.2 Draw the form
FrmDrawForm( form );
// CH.3 Set the focus to our field
FrmSetFocus( form, index );
6. 从contactDetailEventHandler()中删除frmCloseEvent;
7. 从PilotMain()删除MemHandleFree()的函数调用。
本文来源:嵌入式在线 作者:
热点资讯(一周点击率)
最受工程师关注文章
热评博文
快乐大本营
无线时代来临,移动产业生态系统将发生一些根本变化。今日头条推荐“芯片是嵌入式4G技术的关键 产业生态系统将发生变化”。
想了解嵌入式开发工具的市场情况吗?先来体验下我们的在线调查吧!填写调查问卷。

