📄 c++builder (bcb)编程规范 之 鲨鱼美美版.htm
字号:
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">那该怎么办了</SPAN><SPAN
lang=EN-US>? </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">简单把它归到所在单元的类声明中去。函数的实现代码行不要超过</SPAN><SPAN
lang=EN-US>200</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">行</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">包括之间的空格</SPAN><SPAN
lang=EN-US>.</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">因为人的暂时记忆能力不强啊</SPAN><SPAN
lang=EN-US>! </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">为什么文章要分段落啊</SPAN><SPAN
lang=EN-US>! </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">就是人暂存上下文的关联的内存是有限的呀</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT size=2> <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><FONT
color=#4db34d><SPAN lang=EN-US>3 </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">组件的属性设置和数据库的字段表名:</SPAN></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN
lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">一般下都会在对象检查器中的设置。当调试过不去而你又忘记了设置的属性时的哭相,<FONT
id=vhhchaholagb>A网;PW[络KS&9t</FONT>是多么地可气啊!而且</SPAN><SPAN
lang=EN-US>BCB</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">没有组件之间的比较,否则的话可以拖个同样的新组件来比一比到底哪里设置的不同!</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">所以没有办法只好麻烦些直接在代码中设置吧</SPAN><SPAN
lang=EN-US>! </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">虽然很麻烦</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">却可以节省比较可观的时间呀</SPAN><SPAN
lang=EN-US>! </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">要不就像</SPAN>
<SPAN
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体; mso-hansi-font-family: ''''Times New Roman''''; mso-font-kerning: 0pt; mso-ansi-language: ZH-CN">kateboy</SPAN><SPAN
lang=EN-US> (</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">老公</SPAN><SPAN
lang=EN-US>)</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">由于设置了</SPAN><SPAN
lang=EN-US>ADOConnection </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">的</SPAN><SPAN
lang=EN-US>Attrib</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">里中的自动事务处理。每当退出程序时就报错!从早上跑到各大</SPAN><SPAN
lang=EN-US>BCB</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">的</SPAN><SPAN
lang=EN-US>QQ</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">群中求人帮助,只到最后吃晚饭才惊奇发现了毛病所在!</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">还有一次不知那各</SPAN><SPAN
lang=EN-US>BCB</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">老大自报家丑</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">说自己吸了</SPAN><SPAN
lang=EN-US>5</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">包烟抓改</SPAN><SPAN
lang=EN-US>BUG</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">直到凌晨时分,
<P
id=sbcimpmvgairieqcspn>专2+o8'Ae[教w]垠ZizC育D</P>方发现了它,原来是书写错误。</SPAN></FONT>
<P></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN
lang=EN-US><SPAN style="mso-spacerun: yes">
</SPAN></SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">再者就是数据库的表名和字段名。在写数据库中,一般会这样写</SPAN><SPAN
lang=EN-US> </SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT size=2>ADOQuery->SQL->Text=”Select * From
TabName Where Name=’wowo’ and sex=’b’”;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT
size=2>ADOQuery->FieldByName(“Sex”)->AsBoolean=true;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">程序中到处都是这样写,数据库中的字段名一当改变。你得到处去修改,当然用</SPAN><SPAN
lang=EN-US>BCB</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">的查找功能帮一大忙,可是总有漏网之鱼吧!</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">而且</SPAN><SPAN
lang=EN-US>BCB</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">的语法检查不会到字苻串中,每当运行到该处时,虽然程序很明确的告诉你字段不存在,你也很清楚知道如何去修改。但找到它,再一次运行调试。可这段时间以及这时的心情就没有那么好了!每次放同样的错误,每次浪费同样的时间,虽然说少。可每天就</SPAN><SPAN
lang=EN-US>8</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">个小时的工作时间。这样频繁的浪费,心情一次比一次不好了,工作效率就越低,只好晚上加班继续干!若次次因为它要去加班,则那有时间去炮轰美媚啦!更不用说挤出点时间学习啦!身体也每况俞下!</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">解决办法就是使用个单元名为:</SPAN><SPAN
lang=EN-US>DBStruct </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">。在该单元中用结构体来存放数据库的表名和字段。列如:</SPAN><SPAN
lang=EN-US>typedef struct{ stirng Name; string sex;String TabName}
MyTab;</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT size=2>MyTab m_dogTab;</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT
size=2>ADOQuery->FieldByName(m_dogTab.Sex)->AsBoolean=true;
</FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><FONT
color=#5ea25e><SPAN lang=EN-US>4 </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">单元之间的引用</SPAN></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">可以说单元其实就是类,虽然我们写类的时间较少。但</SPAN><SPAN
lang=EN-US>TFORM</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">就是个已经声明好的类,我们就给它添加功能就行了!类之间最好时少耦合,多内聚。最好不要在单元之间使用回调的功能和数据成员。直接使用函数和属性。</SPAN></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><SPAN
lang=EN-US><FONT size=2> <o:p></o:p></FONT></SPAN></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><FONT
color=#55aa55><SPAN lang=EN-US>5</SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">命名</SPAN></FONT></FONT></P>
<P class=MsoNormal style="MARGIN: 0cm 0cm 0pt"><FONT size=2><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">一般下的组件的命名是</SPAN><SPAN
lang=EN-US> Form1 </SPAN><FONT face=宋体><SPAN lang=EN-US
style="FONT-FAMILY: Wingdings; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN
style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">è</SPAN></SPAN><SPAN
lang=EN-US> Frm_Main<SPAN style="mso-spacerun: yes">
</SPAN>Edit1</SPAN><SPAN lang=EN-US
style="FONT-FAMILY: Wingdings; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''; mso-char-type: symbol; mso-symbol-font-family: Wingdings"><SPAN
style="mso-char-type: symbol; mso-symbol-font-family: Wingdings">è</SPAN></SPAN><SPAN
lang=EN-US> Edt_Name </SPAN><SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">等</SPAN>
<SPAN
style="FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">你也可以不缩写!</SPAN></FONT></FONT></P>
<TABLE style="WIDTH: 100%; mso-cellspacing: 0cm" cellSpacing=0
cellPadding=0 width="100%" border=1>
<TBODY>
<TR>
<TD
style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"
colSpan=2>
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 11.25pt"><FONT
size=2><SPAN
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">常用变量命名</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></FONT></P></TD></TR>
<TR>
<TD
style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 57%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"
width="57%">
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 11.25pt"><FONT
size=2><SPAN
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">全局变量</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></FONT></P></TD>
<TD
style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 43%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"
width="43%">
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 11.25pt"><FONT
face=宋体><FONT size=2><SPAN lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black">g_</SPAN><SPAN lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></FONT></FONT></P></TD></TR>
<TR>
<TD
style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 57%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"
width="57%">
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 11.25pt"><FONT
size=2><SPAN
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体; mso-ascii-font-family: ''''Times New Roman''''; mso-hansi-font-family: ''''Times New Roman''''">常量</SPAN><SPAN
lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></FONT></P></TD>
<TD
style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 43%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"
width="43%">
<P class=MsoNormal
style="MARGIN: 0cm 0cm 0pt; LINE-HEIGHT: 11.25pt"><FONT
face=宋体><FONT size=2><SPAN lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black">c_</SPAN><SPAN lang=EN-US
style="FONT-SIZE: 9pt; COLOR: black; FONT-FAMILY: 宋体"><o:p></o:p></SPAN></FONT></FONT></P></TD></TR>
<TR>
<TD
style="BORDER-RIGHT: #d4d0c8; PADDING-RIGHT: 0.75pt; BORDER-TOP: #d4d0c8; PADDING-LEFT: 0.75pt; PADDING-BOTTOM: 0.75pt; BORDER-LEFT: #d4d0c8; WIDTH: 57%; PADDING-TOP: 0.75pt; BORDER-BOTTOM: #d4d0c8; BACKGROUND-COLOR: transparent"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -