如何在delphi中定义控件明类型的变量,可也用(变量名.控件属性)调用变量中存储的控件属性或过程 ( 积分: 100 )

  • 主题发起人 magical_li
  • 开始时间
M

magical_li

Unregistered / Unconfirmed
GUEST, unregistred user!
如何在delphi中定义控件明类型的变量,可也用(变量名.控件属性)调用变量中存储的控件属性或过程。
在VB中只要定义 Object 类型就可以了,
如定义函数:
Function CheckInputSpace(strAlarm As String, objCheckedObject As Object, iError As Integer) As Integer
If (objCheckedObject.Text = &quot;&quot;) And iError <> 1 then

MsgBox &quot;请您输入“&quot;
&amp;
strAlarm &amp;
&quot;”!&quot;, vbOKOnly, &quot;输入错误&quot;
objCheckedObject.SetFocus
CheckInputSpace = 1
else

If (InStr(1, objCheckedObject.Text, &quot;
&quot;, vbTextCompare) > 0) And iError <> 1 then

MsgBox &quot;请不要在“&quot;
&amp;
strAlarm &amp;
&quot;”栏中输入空格!&quot;, vbOKOnly, &quot;输入错误&quot;
objCheckedObject.SetFocus
CheckInputSpace = 1
else

CheckInputSpace = 0
End If
End If
End Function

调用时:CheckInputSpace(&quot;参数代码&quot;, Me.csdm, iCommitError)

在delphi 中如何实现???
小弟是初学者,还请各位大哥指点。第一次提问,如有不到的请原谅
 
如何在delphi中定义控件明类型的变量,可也用(变量名.控件属性)调用变量中存储的控件属性或过程。
在VB中只要定义 Object 类型就可以了,
如定义函数:
Function CheckInputSpace(strAlarm As String, objCheckedObject As Object, iError As Integer) As Integer
If (objCheckedObject.Text = &quot;&quot;) And iError <> 1 then

MsgBox &quot;请您输入“&quot;
&amp;
strAlarm &amp;
&quot;”!&quot;, vbOKOnly, &quot;输入错误&quot;
objCheckedObject.SetFocus
CheckInputSpace = 1
else

If (InStr(1, objCheckedObject.Text, &quot;
&quot;, vbTextCompare) > 0) And iError <> 1 then

MsgBox &quot;请不要在“&quot;
&amp;
strAlarm &amp;
&quot;”栏中输入空格!&quot;, vbOKOnly, &quot;输入错误&quot;
objCheckedObject.SetFocus
CheckInputSpace = 1
else

CheckInputSpace = 0
End If
End If
End Function

调用时:CheckInputSpace(&quot;参数代码&quot;, Me.csdm, iCommitError)

在delphi 中如何实现???
小弟是初学者,还请各位大哥指点。第一次提问,如有不到的请原谅
 
Function CheckInputSpace(strAlarm:String, objCheckedObject:TObject;iError:Integer):Integer;
 
function CheckInputSpace(strAlarm:string;objCheckedObject:Tobject;iError:integer):integer;
begin

with (objCheckedObject as TEdit)do

begin

if (text = '') and (iError <> 1) then

begin

messagebox(handle,'输入错误','请您输入'+ strAlarm + '!',mb_ok+mb_iconError);
setfocus;
CheckInputSpace := 1;
end
else

begin

If (pos(' ',text) > 0) And (iError <> 1) then

begin

messagebox(handle,'输入错误','请不要在'+ strAlarm +'栏中输入空格!',mb_ok+mb_iconError);
SetFocus;
CheckInputSpace = 1;
end
else

CheckInputSpace = 0;
end;

end;

end;
 
假如传进的是一个Tedit,
调用 i := CheckInputSpace(stralarm,Tobject(tEdit1),ierror);
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
1K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
933
SUNSTONE的Delphi笔记
S
S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
I
回复
0
查看
709
import
I
顶部