Delphi 通过脚本 在 设计期 改 控件name 属性

 

program ScriptRenameZL;

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
   TypInfo, ToolsAPI,CnCommon, CnWizUtils,CnWizIdeUtils,IdeInstComp; //IdeInstComp CnWizIdeUtils   CnWizUtils

  { Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
   Dialogs,
  TypInfo, ToolsAPI,CnCommon, CnWizUtils,CnWizIdeUtils;}
var
  //DesignContainer, Comp: TComponent;
  DesignContainer:TCustomForm;
  comp:TWinControl;
  I,CompCount: Integer;
begin
//for I := 0 to Screen.FormCount - 1 do
{
var
  Menu: TMenuItem;
  MainForm: TCustomForm;
  Component: TComponent;
begin
  MainForm := GetIdeMainForm;
  if MainForm <> nil then
  begin
    Component := MainForm.FindComponent(‘HelpMenu‘);
    if Component = nil then
    begin
      ErrorDlg(‘Help Menu NOT Found.‘);
      Exit;
    end;
}

  DesignContainer := IdeGetDesignedForm(form1);  //xe10.1 下不能用,之前在xe7下可以用
  //DesignContainer := GetIdeMainForm;
  //DesignContainer :=  Screen.Forms[0];

  if DesignContainer = nil then
  begin
    showmessage(NO form xxx Found.);
    Exit;
  end;

  CompCount:=  DesignContainer.ComponentCount;
  showmessage(inttostr(compcount));
  for i := 0 to CompCount - 1 do
  begin
     //showmessage(DesignContainer.Components[i].classname);
    if DesignContainer.Components[i].classname=TEdit then
    begin
      showmessage(a);
       GetHzPyW(GetStrProp(DesignContainer.Components[i],caption))
      Comp :=TEdit(DesignContainer.Components[i]);
      SetPropValue(Comp, Name,edtzl+ inttostr(i));
    end;
  end;
   
end.

Delphi 通过脚本 在 设计期 改 控件name 属性

上一篇:C#控件交互效果类(也可以用作缩小面板放大,展示更多信息)


下一篇:Web Storage API:localStorage 和 SessionStorage