Guest:
Register
|
Login
|
Member List
|
Search
|
Statistics
|
FAQ
Language
----------
Simplifed Chinese
Traditional Chinese
English
CnPack Forum
»
CnPack IDE 专家包(CnWizards)
» 求指教--自制脚本重命名特定组件
‹‹ Last Thread
|
Next Thread ››
Poll
Trade
Reward
Activity
Printable Version
|
Email to Friend
|
Subscription
|
Favorites
Subject: 求指教--自制脚本重命名特定组件
ron_xin
新警察
UID 67421
Digest Posts 0
Credits 14
Posts 5
点点分 14
Reading Access 10
Registered 2012-2-17
Status Offline
#1
Post at 2012-2-26 12:22
Profile
|
Blog
|
P.M.
求指教--自制脚本重命名特定组件
/*想用脚本实现类似组件前缀专家的功能,手动对当前窗体特定的组件进行重命名,参考ComponentGrid.pas,但是脚本无法编译通过
提示信息如下:
正在编译...
编译器: [Error] (1:1): 'BEGIN' expected
编译失败
*/
{*******************************************************}
{ }
{ Pascal Script Source File }
{ Run by RemObjects Pascal Script in CnWizards }
{ }
{ Generated by CnPack IDE Wizards }
{ }
{*******************************************************}
program ReNameDBControl;
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
CnWizUtils ,DBCtrls;
var
DesignContainer, Comp: TComponent;
I,CompCount: Integer;
begin
DesignContainer := IdeGetDesignedForm(nil);
if DesignContainer = nil then
begin
ErrorDlg('NO Designer Found.');
Exit;
end;
if DesignContainer.ComponentCount = 0 then
begin
ErrorDlg('NO Component to Process.');
Exit;
end;
for i := 0 to DesignContainer.ComponentCount - 1 do
begin
if DesignContainer.Components[i] is TDBEdit then
begin
Comp :=DesignContainer.Components[i];
SetPropValue(Comp, 'Name','dbedt'+Comp.DataField);
end;
end;
end.
[[i] 本帖最后由 ron_xin 于 2012-2-26 13:28 编辑 [/i]]
ron_xin
新警察
UID 67421
Digest Posts 0
Credits 14
Posts 5
点点分 14
Reading Access 10
Registered 2012-2-17
Status Offline
#2
Post at 2012-2-26 16:05
Profile
|
Blog
|
P.M.
发现,将DBCtrls加入到uses,就会编译失败,不知何故。翻看了论坛所有贴子,只要改DBCtrls改成IdeInstComp 就行了。
[[i] 本帖最后由 ron_xin 于 2012-2-26 18:24 编辑 [/i]]
ron_xin
新警察
UID 67421
Digest Posts 0
Credits 14
Posts 5
点点分 14
Reading Access 10
Registered 2012-2-17
Status Offline
#3
Post at 2012-2-26 18:22
Profile
|
Blog
|
P.M.
{*******************************************************}
{ }
{ Pascal Script Source File }
{ Run by RemObjects Pascal Script in CnWizards }
{ }
{ Generated by CnPack IDE Wizards }
{ }
{*******************************************************}
program ReNameDBControl;
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
CnWizUtils ,TypInfo ,IdeInstComp;
var
DesignContainer, Comp: TComponent;
I,CompCount: Integer;
sDataField: string ;
begin
DesignContainer := IdeGetDesignedForm(nil);
if DesignContainer = nil then
begin
ErrorDlg('NO Designer Found.');
Exit;
end;
if DesignContainer.ComponentCount = 0 then
begin
ErrorDlg('NO Component to Process.');
Exit;
end;
for i := 0 to DesignContainer.ComponentCount - 1 do
begin
if DesignContainer.Components
is TDBEdit then
begin
Comp :=DesignContainer.Components
;
sDataField :=TDBEdit(DesignContainer.Components
).DataField;
SetPropValue(Comp, 'Name','dbedt'+sDataField);
end;
end;
end.
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#4
Post at 2012-2-26 23:26
Profile
|
Blog
|
P.M.
Pascal Script的Uses部分不能随意uses标准库,这是其脚本特性决定的,只能使用我们预注册的unit以及IDE实例内部存在的unit。
DBCtrls此单元我们未在编译期预注册至脚本引擎,因此uses会失败。但uses IdeInstComp后,此单元会将IDE中存在的类都导入脚本引擎,因此可以使用TDBEdit来进行判断。
ron_xin
新警察
UID 67421
Digest Posts 0
Credits 14
Posts 5
点点分 14
Reading Access 10
Registered 2012-2-17
Status Offline
#5
Post at 2012-2-27 23:58
Profile
|
Blog
|
P.M.
再次请教,脚本中好像无法处理DBGrid中的Columns属性性,因为Columns[j].Title.Alignment通常都要设为taCenter,请问没有其他办法可行?
正在编译...
编译器: [Error] (37:37): Unknown identifier 'COLUMNS'
编译失败
for i := 0 to DesignContainer.ComponentCount - 1 do
begin
if DesignContainer.Components[i] is TDBGridEh then
begin
Comp :=DesignContainer.Components[i];
for j := 0 to TDBGridEh(Comp).Columns.count - 1 do
begin
TDBGridEh(Comp).Columns[j].Title.Alignment :=taCenter;
TDBGridEh(Comp).Columns[j].Width :=100;
end;
end;
end;
[[i] 本帖最后由 ron_xin 于 2012-2-28 00:00 编辑 [/i]]
Passion
(LiuXiao)
管理员
UID 359
Digest Posts
19
Credits 6838
Posts 3591
点点分 6838
Reading Access 102
Registered 2004-3-28
Status Offline
#6
Post at 2012-2-29 22:38
Profile
|
Blog
|
P.M.
试一试GetColumns函数来取代Columns属性?脚本似乎对index类型的属性支持不好。
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:29
Powered by
Discuz!
5.0.0
© 2001-2006
Comsenz Inc.
Processed in 0.014388 second(s), 9 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