动态表单生成.dfm以及关联.pas用于二次开发
本文介绍方法一、
新建一个工程文件,建form1,form2,其中form1加入一个按钮控件控件,
写事件如下
uses unit2;
procedure TForm1.Button1Click(Sender: TObject);
begin
Form2.Show;//form2在工程文件中已创建 Application.CreateForm(TForm2, Form2);
WriteComponentResFile('D:\unit2.dfm',form2);
end;
Form2中放置一个pagecontrol1,
写代码如下
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls;
type
TForm2 = class(TForm)
PageControl1: TPageControl;
procedure FormCreate(Sender: TObject);
procedure fButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
fButton:array of array of TButton;
fnewpage:array of TTabSheet;
fstr1,fstr2:array of array of String;
public
procedure ClearControls(AParent: TTabSheet);
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.fButtonClick(Sender: TObject);
var
s,s1,s2:string;
i,j,x:Integer;
begin
//
s:= (Sender as TButton).Name;
x:=pos('j',s);
s1:=copy(s,4,x-4);
s2:=copy(s,x+1,length(s)-x);
i:=strtoint(s1);
j:=strtoint(s2);
showmessage(s);
end;
procedure TForm2.FormCreate(Sender: TObject);
const
col2=5;
lrAside=10;
width1=160;
height1=40;
btnMagins=20;
var
sc,sc1:string;
rc,rd:Integer;
i,j:Integer;
st:String;
begin
begin
rc:=10;
SetLength(fnewpage,rc);
SetLength(fButton,rc);
SetLength(fstr1,rc);
SetLength(fstr2,rc);
for I := 0 to rc-1 do begin
fnewpage[I]:=TTabSheet.Create(pagecontrol1);
sc1:='测试模块'+inttostr(I);
fnewpage[I].Caption:=sc1;
fnewpage[i].Name:='fsc'+inttostr(i);
fnewpage[I].PageControl:= PageControl1;
PageControl1.ActivePage:=fnewpage[I];
rd:=20;
SetLength(fButton[I],rd);
SetLength(fstr1[I],rd);
SetLength(fstr2[I],rd);
for J := low(fButton[I]) to high(fButton[I]) do
begin
fButton[i,j]:=TButton.Create(self);
fButton[i,j].Parent:=fnewpage[i];
fButton[i,j].Caption:='测试按钮('+inttostr(I)+':'+inttostr(J)+')';
fButton[i,j].Name:='fcx'+inttostr(i)+'j'+inttostr(j);
fButton[i,j].top:= ((J) div col2) * (height1+ lrAside) + lrAside ;
fButton[i,j].Left:=((J) mod col2) * (width1 + btnMagins) + lrAside;
fButton[i,j].Width:=width1;
fButton[i,j].Height:=height1;
st:='test'+ inttostr(I)+'j'+inttostr(J) ;
fButton[i,j].hint:=st;
fButton[i,j].OnClick:=fButtonClick;
end;
end;
end;
end;
procedure TForm2.FormDestroy(Sender: TObject);
var
I:Integer;
begin
for I :=High(fnewpage) downto Low(fnewpage) do
begin
ClearControls(fnewpage[i]);
fnewpage[i].Free;
end;
end;
procedure TForm2.ClearControls(AParent: TTabSheet);
var
i: Integer;
begin
for i := AParent.ControlCount - 1 downto 0 do begin
if not AParent.Controls[i].InheritsFrom(TWinControl) then Continue;
try
if TWinControl(AParent.Controls[i]).ControlCount > 0 then begin
ClearControls(TTabSheet(AParent.Controls[i]));
end;
AParent.Controls[i].Free;
except
end;
end;
end;
end.
运行form1,按下form1的按钮控件,会在d:\根目录地下生成unit2.dfm,只有.dfm文件没有关联的pas怎么办。拷贝上面的.pas文件,代码删除掉动态生成控件的部分,如下所示:
unit Unit2;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ComCtrls, Vcl.StdCtrls;
type
TForm2 = class(TForm)
PageControl1: TPageControl;
procedure FormCreate(Sender: TObject);
procedure fButtonClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
public
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
procedure TForm2.fButtonClick(Sender: TObject);
var
s,s1,s2:string;
i,j,x:Integer;
begin
//
s:= (Sender as TButton).Name;
x:=pos('j',s);
s1:=copy(s,4,x-4);
s2:=copy(s,x+1,length(s)-x);
i:=strtoint(s1);
j:=strtoint(s2);
showmessage(s);
end;
procedure TForm2.FormCreate(Sender: TObject);
begin
//
end;
procedure TForm2.FormDestroy(Sender: TObject);
begin
//
end;
end.
此时的form2是如下表单模样
在新建的工程文件中打开这个unit2.pas和unit2.dfm,就可以正常设计和修改了
动态表单生成.dfm以及关联.pas用于二次开发相关推荐
- Delphi自编程序生成.dfm以及关联.pas的方法二
Delphi自编程序生成.dfm以及关联.pas的方法二 前面介绍了方法一,现在介绍方法二 首先,编写一个工具,方便通过模板生成动态dfm文件,工具内容如下: 新建工程文件,form1上放置一个按钮B ...
- Angular动态表单生成(八)
动态表单生成之拖拽生成表单(下) 我们的动态表单,最终要实现的效果与Form.io的在线生成表单的效果类似,可以参考它的demo地址:https://codepen.io/travist/full/x ...
- html5 前端动态加载后端,Vue+Element的动态表单,动态表格(后端发送配置,前端动态生成)...
vue+element的动态表单,动态表格(后端发送配置,前端动态生成) 动态表单生成 elementui官网引导 关键配置 template中,form和form-item的写法和绑定 data里的 ...
- Vue.js+ElementUI+vant生成动态表单配置
前言 我司最近在搭建一款后台管理系统,使用的是Vue全家桶配合Element-ui,遇到一个问题,需要处理很多的表单,所以想到的解决方案是通过后台配置生成动态表单,这对于我来说也算是新的挑战,涉及的功 ...
- java中显示动态信息的方法_java里的动态表单技术
最近的一个项目,由于客户的需求等信息不确定,为了降低以后修改的成本及产品的推广考虑到动态表单技术,之前也一直在考虑到动态表单技术,毕竟在delphi里已经实现过了,由于我们采用的hibernate的执 ...
- LeaRun.net快速开发动态表单
表单,在网页技术中,主要负责数据传输,是通过浏览器或APP,显示.收集.提交信息到服务器上,如我们常用的用户注册.在线联系.在线故障受理等都是在线表单的具体应用形式. 在信息化建设过程中,存在大量前端 ...
- 碎片数据收集利器-结构化动态表单设计思路
本文基于面向基本公共卫生的业务系统设计经验,抽象出一套适合大型ERP系统的表单业务数据模型,目标是最大限度保留系统弹性的同时,尽可能降低系统复杂度和开发成本.enjoy~ 背景 填写表单应该是所有业务 ...
- angular4更改表单中显示的值_Angular 4 动态表单教程 Reactive Forms教程
动态表单(React Forms)是一种动态构建表单的技术,用于解决有时候手动编写和维护表单所需工作量和时间会过大的问题.特别是在需要编写大量表单时.表单都很相似,而且随着业务和监管需求的迅速变化,表 ...
- element手机验证格式_基于Vue+elementUI实现动态表单的校验功能(根据条件动态切换校验格式)...
前言 开发过程中遇到了一个需求,根据用户选择的联系方式,动态改变输入框的检验条件,并且整个表单是可以增加的 在线访问:动态表单校验 github(欢迎star): https://github.com ...
最新文章
- 世上最伟大的十个公式,1+1=2排名第七,质能方程排名第五
- H3C无线 AC网关式部署无线开局(WEB版)
- css行高line-height的一些深入理解及应用
- ubuntu下使用ppa安装codeblocks集成开发环境
- VMWare虚拟系统上网设置及VMWare虚拟机三种工作模式详解
- C++实现的Miller-Rabin素性测试程序
- 如何备份MySql的数据库
- 快递规模持续扩大,丰网加盟迎发展新机遇
- xls文件格式与扩展名不匹配php,excel表格的文件格式和扩展名不匹配怎么办
- 服务器inetpub是什么文件夹,处理inetpub文件夹在win10中的问题
- java---File类笔记(简单介绍)
- 机械设计基础B【4】齿轮安装传动
- 钉钉小程序-打开外部链接(文件链接)
- MySQL增加、修改、删除字段
- 用css解决Unigui在IE系列浏览器中字体变小的问题
- 区块链让知识产权保护更容易
- [Vue warn]: Unknown custom element: <mycom> - did you register the component correctly? For recursiv
- Android 开发技术趋势
- Shell扩展正则表达式练习1——电话号码过滤
- elementui from表单提交_vue+element-ui el-form表单验证及提交验证
热门文章
- 我的世界优化模组推荐:1.19.2 Fabric优化模组
- 怎么画单极交流放大电路波形图_什么是交流电;什么是直流电
- intel optane(tm) memory pinning无法加载 | Windows更新后右键打开文件报错
- 汇川 PLC H2U3232MR-XP 改脉冲输出
- List集合删除指定对象,使用removeIf
- STM32CubeMx使用教程(五)—— 使用PWM控制蜂鸣器演唱孤勇者
- vue-element-admin 跳过登录权限
- CLIP-Event: Connecting Text and Images with Event Structures 论文解读
- 少一些计较多_人生多一些宽容,少一些计较!
- 乐高收割机器人_学习乐高机器人课程孩子能收获什么