⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 206.htm

📁 水木清华的BBS文章
💻 HTM
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>CTerm非常精华下载</title>
</head>
<body bgcolor="#FFFFFF">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="577">
<tr><td width="32%" rowspan="3" height="123"><img src="DDl_back.jpg" width="300" height="129" alt="DDl_back.jpg"></td><td width="30%" background="DDl_back2.jpg" height="35"><p align="center"><a href="http://bbs.tsinghua.edu.cn"><font face="黑体"><big><big>水木清华★</big></big></font></a></td></tr>
<tr>
<td width="68%" background="DDl_back2.jpg" height="44"><big><big><font face="黑体"><p align="center">         Delphi编程                            (BM: strayli FlyingBoy)          </font></big></big></td></tr>
<tr>
<td width="68%" height="44" bgcolor="#000000"><font face="黑体"><big><big><p   align="center"></big></big><a href="http://cterm.163.net"><img src="banner.gif" width="400" height="60" alt="banner.gif"border="0"></a></font></td>
</tr>
<tr><td width="100%" colspan="2" height="454"> <p align="center">[<a href="index.htm">回到开始</a>][<a href="178.htm">上一层</a>][<a href="207.htm">下一篇</a>]
<hr><p align="left"><small>发信人: fuse (保险丝), 信区: Visual <br>

标  题: Re: 在Delphi中动态生成的控件怎么响应消息? <br>

发信站: BBS 水木清华站 (Thu Nov  6 16:02:51 1997) <br>

  <br>

【 在 FlyingBoy (一飞冲天鹰中王) 的大作中提到: 】 <br>

:                                      ^^^^^^^^^^^^^ <br>

:                                      不会吧,Help中好象说tag属性是没用的 <br>

:                                      只是一个为了兼容而声明的整数变量 <br>

  <br>

Control array emulation <br>

  <br>

Q.    "Is it possible to create something akin to the control array in VB? For eexample, I want an group of buttons with a common event handler whereby the event handler picks up an integer value for the particular button. In VB this would be done via <br>

the control array  index." <br>

  <br>

A.    One way do to this is to set the Tag field for each button to a different number and then create a common OnClick event handler that looks at the Sender's (as a TButton) Tag field.  Assign the same OnClick event handler to all the buttons in the <br>

group.  The OnClick event handler would look something like this: <br>

  <br>

  procedure TForm1.Button1Click(Sender: TObject); var cap: string; <br>

  begin <br>

    case TButton(sender).Tag of <br>

      1: ShowMessage('1st Button Pressed'); <br>

      2: ShowMessage('2nd Button Pressed'); <br>

      3: ShowMessage('3rd Button Pressed'); <br>



    end; <br>

  end; <br>

  <br>

Q:  I spend alot of time checking datatypes so that accessing the same property <br>

of different objects does GPF. <br>

  <br>

The code tends to look like this: <br>

  <br>

fldname:=''; <br>

fld:=Components[I]; <br>

if (Components[I] is TDBedit) then <br>

  <br>

   fldname:=TDBEdit(fld).DataField <br>

else if (Components[I] is TDBLookupList) then <br>

   fldname:=TDBlookupList(fld).DataField <br>

else if (Components[I] is TDBLookupCombo)then <br>

   fldname:=TDBlookupCombo(fld).DataField <br>

else if (Components[I] is TDBListBox) then <br>

   fldname:=TDBListBox(fld).DataField <br>

else if (Components[I] is TDBComboBox) then <br>

   fldname:=TDBComboBOx(fld).DataField <br>

else if (Components[I] is TDBCheckBox) then <br>

else if (Components[I] is TDBCheckBox) then <br>

   fldname:=TDBCheckBox(fld).DataField <br>

else if (Components[I] is TDBRadioGroup) then <br>

  <br>

   fldname:=TDBRadioGroup(fld).DataField <br>

else if (Components[I] is TDBMemo) then <br>

   fldname:=TDBMemo(fld).DataField; <br>

  <br>

Is there a way to use the classtype property in a case statement? <br>

Would that be better? <br>

  <br>

  <br>

A:  No and yes.  I suggest that you declare constants that represent each class. <br>

  <br>

const <br>

  val_TEdit = 1; <br>

  val_TButton = 2; <br>

{etc, etc} <br>

  <br>

Then, set the tag of each object to equal the object's constant.  Then the case statement is easy. <br>

  <br>

case (sender as tComponent).tag of <br>

{ . . . } <br>

   fldname:=TDBMemo(fld).DataField; <br>

  <br>

Is there a way to use the classtype property in a case statement? <br>

Would that be better? <br>

  <br>

  <br>

A:  No and yes.  I suggest that you declare constants that represent each class. <br>

  <br>

const <br>

  val_TEdit = 1; <br>

  val_TButton = 2; <br>

{etc, etc} <br>

  <br>

Then, set the tag of each object to equal the object's constant.  Then the case <br>

  <br>

case (sender as tComponent).tag of <br>

{ . . . } <br>

end; <br>

  <br>

{ This code came from Lloyd's help file! } <br>

  <br>

-- <br>

※ 来源:·BBS 水木清华站 bbs.net.tsinghua.edu.cn·[FROM: 210.32.151.168] <br>

</small><hr>
<p align="center">[<a href="index.htm">回到开始</a>][<a href="178.htm">上一层</a>][<a href="207.htm">下一篇</a>]
<p align="center"><a href="http://cterm.163.net">欢迎访问Cterm主页</a></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -