gpt4 book ai didi

delphi - 检查编辑是否为空的最佳做法是什么

转载 作者:行者123 更新时间:2023-12-03 19:03:10 24 4
gpt4 key购买 nike

我想知道验证编辑是否为空的最佳做法

  if edt1.Text <> '' then
//DoSomething
else
ShowMessage('Check 1');

if edt1.Text = '' then
ShowMessage('Check 2')
else
//DoSomething

最佳答案

读取 Text 属性会将 Edit 的当前内容作为临时 String 加载到内存中。如果您只想检查 Edit 是否为空,有一种更有效的方法:

if edt1.GetTextLen > 0 then
// not empty
else
// empty

当然,如果 Edit 包含任何字符,即使只是空格,长度也会是 > 0。如果您需要忽略前导/尾随空格,您别无选择,只能检索完整的 Text 并修剪它:

if Trim(edt1.Text) <> '' then
// not empty
else
// empty

关于delphi - 检查编辑是否为空的最佳做法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26914324/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com