Guest:
Register
|
Login
|
Member List
|
Search
|
Statistics
|
FAQ
Language
----------
Simplifed Chinese
Traditional Chinese
English
CnPack Forum
»
CnVCL 组件包
» 关于CnOptionGroup字符为密码时,该如何隐藏字符
‹‹ Last Thread
|
Next Thread ››
Poll
Trade
Reward
Activity
Printable Version
|
Email to Friend
|
Subscription
|
Favorites
Subject: 关于CnOptionGroup字符为密码时,该如何隐藏字符
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#1
Post at 2009-2-21 09:06
Profile
|
Blog
|
P.M.
关于CnOptionGroup字符为密码时,该如何隐藏字符
with Option.AddGroup('用户登录设置') do
begin
AddItem(GmConfig,'UserName','用户名');
AddItem(GmConfig,'passowrd','密码');
end;
在设置时密码以明文显示,请问该如何隐藏密码
[
本帖最后由 雨中雪 于 2009-2-21 09:08 编辑
]
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#2
Post at 2009-2-21 09:10
Profile
|
Blog
|
P.M.
function TCnOptionGroup.AddItem(AInstance: TObject; const APropName: string;
const AText: string; const AList: string; ADefaultValue, AMinValue,
AMaxValue: Variant): TCnOptionItem;
如何加入一参数标识是否是密码:APassWord:boolean
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#3
Post at 2009-2-21 11:04
Profile
|
Blog
|
P.M.
组件包本身不具有这个功能,需要自行修改代码以实现它。
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#4
Post at 2009-2-22 13:16
Profile
|
Blog
|
P.M.
我尝试着增加以下
procedure TCnOptionItem.setPasswordChar(const Value: string);
begin
FPasswordChar := Value;
end;
function TCnOptionItem.GetPasswordChar: string;
begin
if not VarIsNull(FPasswordChar) then
Result := FPasswordChar
else
Result := '#0';
end;
在TCnOptionItem = class(TCnBaseOption)的published中增加
property PassWordChar: string read GetPassWordChar write SetPassWordChar;
{* 关联对象属性密码掩码 }
不知道还要增加哪些代码,请指教!
[
本帖最后由 雨中雪 于 2009-2-22 13:17 编辑
]
zjy
管理员
UID 2
Digest Posts
6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
#5
Post at 2009-2-25 22:05
Profile
|
Site
|
Blog
|
P.M.
代码已更新
请从 CVS 中更新 CnPack 最新的代码。
此次更新为 TCnAOTreeView 增加了一个 OnCreateInplaceEdit 事件,针对密码框的示例如下:
procedure TForm1.OnCreateInplaceEdit(Sender: TObject;
InplaceEdit: TControl; AOption: TCnBaseOption);
begin
if (InplaceEdit is TCustomEdit) and (AOption is TCnOptionItem) and
SameText(TCnOptionItem(AOption).PropName, 'Password') then
TEdit(InplaceEdit).PasswordChar := '*';
end;
详见 Demo 程序。
Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#6
Post at 2009-2-26 10:52
Profile
|
Blog
|
P.M.
CVS登录不上,说用户名和密码不正确
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#7
Post at 2009-2-26 11:06
Profile
|
Blog
|
P.M.
请问是否参考了此贴?
http://bbs.cnpack.org/viewthread.php?tid=1882&extra=page%3D1
如果是按里头做的,烦请贴出出错信息看看?
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#8
Post at 2009-2-26 11:41
Profile
|
Blog
|
P.M.
这句能不能改成这样的:
if (InplaceEdit is TCustomEdit) and (AOption is TCnOptionItem) and
(pos('password',TCnOptionItem(AOption).PropName)>0) then
TEdit(InplaceEdit).PasswordChar := '*';
这样就不会局限于密码的属性必须为Password,只要属性中包含password就是密码输入框,就以*显示文本内容。
[
本帖最后由 雨中雪 于 2009-2-26 14:02 编辑
]
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#9
Post at 2009-2-26 11:45
Profile
|
Blog
|
P.M.
我刚才作了以下测试:发现以下问题:
图一是正常显示时,密码确以明文显示出来;
图二为在输入密码时显示是正确的;
[
本帖最后由 雨中雪 于 2009-2-26 11:46 编辑
]
Image Attachment
:
2.png
(2009-2-26 11:45, 562 bytes)
Image Attachment
:
1.png
(2009-2-26 11:45, 950 bytes)
zjy
管理员
UID 2
Digest Posts
6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
#10
Post at 2009-2-26 21:18
Profile
|
Site
|
Blog
|
P.M.
又增加了一个新事件
procedure TForm1.OnGetItemText(Sender: TObject; AOption: TCnOptionItem;
var AText: string);
begin
if SameText(TCnOptionItem(AOption).PropName, 'Password') then
AText := '******';
end;
实际使用时事件处理代码可根据需要来调整,用 Pos 当然也是可以的,Demo 中只是一个示例。
用这个事件除了可以处理密码,还可以用来为某些属性定制特殊的显示内容,比如日期格式、浮点数格式格式等。
PS: 之所以用增加事件的方法来解决这些问题,主要是这一类的需求可能很多,事件用起来虽然比较麻烦,但可以灵活控制。
Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#11
Post at 2009-2-27 21:54
Profile
|
Blog
|
P.M.
刚才做了一下测试,发现还有问题:
在程序创建后密码还是以明文显示,编辑后或获得焦点离开后,密码才以*号显示。
zjy
管理员
UID 2
Digest Posts
6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
#12
Post at 2009-2-28 11:09
Profile
|
Site
|
Blog
|
P.M.
可能跟事件定义顺序有关
如果你是动态关联事件的话,应该先关联事件,再设置Options属性。
Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#13
Post at 2009-2-28 11:38
Profile
|
Blog
|
P.M.
还想问一下, OnCreateInplaceEdit和OnGetItemText在Events列表中怎么没有呀
zjy
管理员
UID 2
Digest Posts
6
Credits 2385
Posts 1543
点点分 2385
Reading Access 102
Registered 2002-12-16
Location China
Status Offline
#14
Post at 2009-2-28 12:33
Profile
|
Site
|
Blog
|
P.M.
如果已经安装过cnpack控件包
需要重新编译安装一次才会有。
Zhou JingYu
CnPack Administrator
http://www.cnpack.org/
雨中雪
普通灌水员
UID 41830
Digest Posts 0
Credits 79
Posts 29
点点分 79
Reading Access 10
Registered 2009-2-19
Status Offline
#15
Post at 2009-3-2 08:42
Profile
|
Blog
|
P.M.
谢谢管理员
Poll
Trade
Reward
Activity
CnPack Forum
CnPack English Forum
> CnWizards IDE Wizards
> CVSTracNT
> Announcements & Others
All times are GMT++8, the time now is 2024-11-22 18:05
Powered by
Discuz!
5.0.0
© 2001-2006
Comsenz Inc.
Processed in 0.017998 second(s), 10 queries , Gzip enabled
TOP
Clear Cookies
-
Contact Us
-
CnPack Website
-
Archiver
-
WAP
Member's CP Home
Edit Profile
Credits Transaction
Public User Groups
Buddy List
Main
Page Views
User Agents
Posts History
Top Forums
Top Threads
Post Ranking
Credit Ranking
Online Time
Team
Moderation Stats