中国开发网: 论坛: 程序员情感CBD: 贴子 708241
haitao
嗯,对外可以没有类,直接封装为一个函数
不过库的实现里还是使用了一个类,专门为此定义一个类,就觉得有点不爽
建立form 是完全可以不用类也不用dfm的,只是动态创建的form里的按钮事件需要一个对象的方法去挂接——直接的做法是为此建立一个类。。。。。。

所以我说:为这个(按钮事件需要一个对象的方法去挂接)专门定义一个类、创建一个对象、最后释放,感觉是不如method.code(直接挂接一个普通的函数)美观、方便 (空) (haitao [2] 今天 18:12)

而我实际使用的最终版本,既没有定义一个类,也没有使用method.code这样的做法
interface

function SelectMultBox(ss:String;t:String;default:String):String;
function SelectOneBox(ss:String;t:String;default:Integer):Integer;


implementation

const
clbname='select2';
function createForm2Button(ss:String;t:String;b1:Boolean;d1:Integer;d2:String):Tform;
var
p:Tchecklistbox;
pb:Tpanel;
begin
result:=Tform.Create(nil);
result.Position:=poMainFormCenter;
result.Caption:=t;
pb:=Tpanel.Create(result);
pb.Parent:=result;
pb.Height:=30;
pb.Align:=albottom;

with Tbitbtn.Create(result) do
Begin
kind:=bkOK;
parent:=pb;
pb.height:=height+10;
top:=5;
left:=pb.Width-200;
anchors:=[aktop,akright];
caption:='确认';
End;
with Tbitbtn.Create(result) do
Begin
kind:=bkCancel;
parent:=pb;
top:=5;
left:=pb.Width-100;
anchors:=[aktop,akright];
caption:='取消';
End;

if b1 then
with Tradiogroup.Create(result) do
Begin
parent:=result;
Align:=alclient;
items.Text:=ss;
itemindex:=d1;
name:=clbname;
End
else
Begin
p:=Tchecklistbox.Create(result);
with p do
Begin
parent:=result;
Align:=alclient;
items.Text:=ss;
checklistbox.str2checklist(d2,p);
name:=clbname;
End;
End;

end;


function SelectOneBox(ss:String;t:String;default:Integer):Integer;
var
f:Tform;
begin
f:=createForm2Button(ss,t,true,default,'');
result:=-2;
if f.ShowModal=mrOK then
Begin
result:=Tradiogroup(f.FindComponent(clbname)).ItemIndex;
End;
//f.close; //这行可以省掉
f.free;
end;
function SelectMultBox(ss:String;t:String;default:String):String;
var
f:Tform;
begin
f:=createForm2Button(ss,t,false,0,default);
result:='';
if f.ShowModal=mrOK then
Begin
result:=checklistbox.checklist2str(Tchecklistbox(f.FindComponent(clbname)));
End;
//f.close; //这行可以省掉
f.free;
end;
我的blog:http://szhaitao.blog.hexun.com & http://www.hoolee.com/user/haitao
--以上均为泛泛之谈--
不尽牛人滚滚来,无边硬伤纷纷现 人在江湖(出来的),哪能不挨刀(总归是要的)
网络对话,歧义纷生;你以为明白了对方的话,其实呢?

您所在的IP暂时不能使用低版本的QQ,请到:http://im.qq.com/下载安装最新版的QQ,感谢您对QQ的支持和使用

相关信息:


欢迎光临本社区,您还没有登录,不能发贴子。请在 这里登录