95 lines
2.5 KiB
Plaintext
95 lines
2.5 KiB
Plaintext
type E_ListBoxmain=class(tdcreateform)
|
|
uses tslvcl;
|
|
listbox1:tlistbox;
|
|
btn1:tbtn;
|
|
btn2:tbtn;
|
|
btn3:tbtn;
|
|
btn4:tbtn;
|
|
btn5:tbtn;
|
|
btn6:tbtn;
|
|
function Create(AOwner);override; //构造
|
|
begin
|
|
inherited;
|
|
end
|
|
function btn6_clk(o;e);virtual; //选择当前选中项的后一项
|
|
begin
|
|
if listbox1.Multisel=0 then
|
|
begin
|
|
idx := listbox1.getCurrentSelection();
|
|
nidx := (idx+1+listbox1.ItemCount) mod listbox1.ItemCount;
|
|
listbox1.setCurrentSelection(nidx);
|
|
end
|
|
end
|
|
function btn5_clk(o;e);virtual; //在选中项前插入
|
|
begin
|
|
listbox1.insertItem(datetimetostr(now()),listbox1.getCurrentSelection());
|
|
end
|
|
|
|
function btn4_clk(o;e);virtual; //在最后加入
|
|
begin
|
|
listbox1.appendItem(datetimetostr(now()));
|
|
end
|
|
function btn3_clk(o;e);virtual; //多选单选设置
|
|
begin
|
|
if o.caption="多选/(单选)" then
|
|
begin
|
|
listbox1.Multisel := 1;
|
|
o.caption :="(多选)/单选";
|
|
end else
|
|
begin
|
|
listbox1.Multisel := 0;
|
|
o.caption :="多选/(单选)"
|
|
end
|
|
end
|
|
|
|
function btn2_clk(o;e);virtual; //删除选中
|
|
begin
|
|
listbox1.DeleteSelectedItems();
|
|
end
|
|
function btn1_clk(o;e);virtual; //初始化数据
|
|
begin
|
|
InitListData();
|
|
end
|
|
function InitListData();
|
|
begin
|
|
listbox1.Items := array(
|
|
"龙岗区",
|
|
"盐田区",
|
|
"坪山区",
|
|
"大鹏新区",
|
|
"深汕特别合作区",
|
|
"宝安区",
|
|
"光明区",
|
|
"南山区",
|
|
"福田",
|
|
"南山"
|
|
);
|
|
end
|
|
function e_listboxmain1_close(o;e);virtual;
|
|
begin
|
|
{**
|
|
@explan(说明) 主窗口关闭回调 %%
|
|
@param(e)(tuievent) 消息对象 %%
|
|
@param(o)(ttimer) 当前主窗口 %%
|
|
**}
|
|
if MessageBoxA('是否关闭当前窗口','关闭',MB_YESNO,o)<>IDYES then e.skip := true;
|
|
|
|
end
|
|
function DoControlAlign();override;//对齐子控件
|
|
begin
|
|
//当窗口大小改变时,该函数会被调用,
|
|
//可以通过 clientrect 获取客户区大小,设置子控件的位置以及大小
|
|
//如果自己处理了子控件的对齐,就可以去掉 inherited
|
|
inherited;
|
|
end
|
|
function Recycling();override; //回收变量
|
|
begin
|
|
inherited;
|
|
ci := self.classinfo(); //将成员变量赋值为nil避免循环引用
|
|
for i,v in ci["members"] do
|
|
begin
|
|
invoke(self,v["name"],nil);
|
|
end
|
|
end
|
|
end
|