📄 用delphi设计拨动、跳线开关组件.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Welcome to Delphi Tips !</title>
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<link rel="stylesheet" href="../tips.css"></head>
<body bgcolor="#D8D0C8" text="#675350">
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="579" height="63" bordercolorlight="#784400" bordercolordark="#D8D0C8">
<tr>
<td width="194" height="86"><img src="../images/title.gif" width="340" height="85"></td>
<td width="377" height="86" valign="top"><img src="../images/dong.jpg" width="251" height="85">
</td>
</tr>
</table>
<br>
</div>
<div align="left">
<table border="1" cellpadding="0" cellspacing="0" width="578" height="18" bordercolorlight="#784400" bordercolordark="#CCCCCC" class="p2">
<tr bgcolor="#B0A498">
<td width="574" height="18"> ><a href="../index.htm">DelphiTips首页</a>
> <a href="main.htm">控件应用</a></td>
</tr>
</table>
<br>
<table width="96%" border="1" bordercolorlight="#784400" cellspacing="0" bordercolordark="#D8D0C8">
<tr bgcolor="#B0A498" class="p1">
<td colspan="3">
<div align="center">用Delphi设计拨动、跳线开关组件</div>
</td>
<td width="12%" class="p2"><<<a href="006.htm">上一篇</a></td>
<td width="13%" class="p2"><a href="008.htm">下一篇</a>>></td>
</tr>
<tr class="p2">
<td colspan="5">
<table width="100%" border="0" class="p2">
<tr>
<td width="3%"> </td>
<td width="94%"><span class="p2">昆明贵金属研究所所办公室<br>
马骏<br>
----计算机测控系统中常使用各种计算机测试板卡,在这些板卡上多设有各种编码和跳线开关。在编写与之配用的测控程序时,常需编写这些开关操作时的相应程序,如果有一个编码或跳线开关组件是十分有帮助的。以下是我用Delphi编写的一个BiSwitch控件。<br>
<br>
----此控件由TGraphicControl继承而来,具有常用的属性,如Enabled、Tag、Hint等,此外新增加了State,Color属性。对于编码和跳线开关,只有两个状态(ON和OFF),在预先编辑好的资源文件中存有开关在不同状态下的图片,当开关改变状态时将相应的图形显示出来,开关在屏幕上就能被“拨动”了。Color属性用于开关的背景与窗口背景颜色配合,取红色有较好的视觉效果,绿色和黄色是电<br>
路板常用的保护漆色,当Form被模拟成电路板时这会有所帮助(通过修改资源文件可以得到你想要的开关颜色和形状)。<br>
<br>
----DIP封装的编码开关有4位、8位、12位等规格,跳线开关则可以任意数量使用。将BiSwitch组合使用就可以满足不同位数的要求,所附的SWITCH程序中就有一个8位编码开关的例子,效果如图。下面以双诺公司的AC1032数字I/O卡上的SW1开关说明使用方法,SW1用于设定测试卡在计算机中的基址,其开关SW1的位2确定基址的位10,开关位8确定基址的位4,基址位10以上接地,位4以下供测试卡自用,基址调节范围从210H-7F0H。为了使编码开关的拨动与基址对应起来,将每一个BiSwitch的Tag属性赋值为相应基址位的数值,如开关位8的Tag值为4,开关位1未使用Tag为0。在每一个BiSwitch的OnClick事件中都调用doSwitch来响应。<br>
</span>
<p><span class="p2">Procedure doSwitch<br>
var<br>
bs : TBiSwitch;<br>
begin<br>
bs := (Sender as TBiSwitch);<br>
{改变开关的显示状态 }<br>
bs.State := not bs.State;<br>
<br>
{根据Tag的值确定新的基址 }<br>
if bs.Tag >0 then<br>
begin<br>
{ HiByte, LoByte为窗体的私有变量作为中间变量计算基址 }<br>
if bs.Tag >7 then HiByte.SetBit( bs.Tag-8 )<br>
else
LoByte.SetBit( bs.Tag );<br>
end;<br>
<br>
{将新的基址赋值给测试卡 }<br>
pc1032.SetAddress(HiByte.FValue * 256 + LoByte.FValue);<br>
{在窗体中显示新的地址 }<br>
lbAddress.Caption := Format<br>
('BaseAddress is %xH', [pc1032.GetAddress]);<br>
end;</span>
</td>
<td width="3%"> </td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#B0A498" class="p2">
<td height="22" width="61%" colspan="2"> <marquee behavior="alternate">如果你有什么好的资料,可以寄给我哟:)</marquee></td>
<td height="22" width="14%"><a href="../index.htm"><<回到首页</a></td>
<td height="22" width="12%"><<<a href="006.htm">上一篇</a></td>
<td height="22" width="13%"><a href="008.htm">下一篇</a>>></td>
</tr>
</table>
<br>
<br>
<hr size=1 noshade width=500>
<table width="75%" border="0" align="center" class="p2">
<tr>
<td colspan="2"> </td>
<td width="24%">
<table width="95%" border="1" bordercolorlight="#663300" bordercolordark="#CCCCCC" cellspacing="0" class="p2">
<tr>
<td>
<div align="center">Delphi 技巧集</div>
</td>
</tr>
</table>
</td>
<td width="38%"> </td>
</tr>
<tr>
<td width="16%"> </td>
<td colspan="2">Copyright 1999.11 by 东子</td>
<td width="38%"><a href="../jintongbao@188.net">Mail to me!</a></td>
</tr>
<tr>
<td colspan="4">
<div align="center">感谢广州视窗提供主页空间</div>
</td>
</tr>
</table>
<br>
</div><div align="center"><center>
</center></div>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -