i:=1;//控制换行的变量 for j := 1 to 40 do//开始创建 begin tpl[j]:=Tpanel.Create(self); tpl[j].Parent:=ScrollBox1; tpl[j].Height:=30; tpl[j].Width:=55; tpl[j].ShowHint:=true; tpl[j].BevelOuter:=bvnone; if j mod n=0 then//控制换行 begin tpl[j].Top:=i*33; tpl[j].left:=tpl[j-1].left+58; i:=i+1; end else if j mod n =1 then begin tpl[j].left:=1; tpl[j].Top:=i*33; end else begin tpl[j].Top:=i*33; tpl[j].left:=tpl[j-1].left+58; end;
Delphi的VCL大部分不是线程安全,你在一个线程里面全部创建了,显示还是要靠主线程,我想这个速度好不到哪里去。我不太相信创建1000个Panel会慢到用户有感觉? Panels:array[0..999] of TPanel for i:=0 to 999 do Panles[i]:=TPanle.Create(nil); 我试了下,是0.01秒。再加上全部设完Parent,也就0.6秒多
问个别的问题: Adoquery查询到的数据集可以重复使用吗?例如我在button1的onclick事件中编写了Adoquery1的sql语句。那么我在button2里的onclick事件中能不能直接就这样调用: For i=0 to Adoquery1.Recordcount-1 do begin ...//对数据集的一些操作; end; 我这样直接使用adoquery1的数据集的话,显示出来的不是在button1事件中的哪些数据,好奇怪。不知道怎样才能得到Adoquery1最后一次查询到的值?????
m_Panel: TPanel;
public Constructor Create(AOwner:TComponent);
Destructor Destroy;override;......
constructor TReceiveFile.Create(AOwner: TComponent;SaveFileName:string);
begin
m_Panel:= TPanel.Create(AOwner);
inherited Create( false );
end;destructor TReceiveFile.Destroy;
begin
m_Panel.Destroy;
inherited;
end;
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs;type
TForm1 = class(TForm)
private
m_Panel:TPanel;
{ Private declarations }
public
Constructor Create(AOwner:TComponent);
Destructor Destroy;override;
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
constructor TReceiveFile.Create(AOwner: TComponent;SaveFileName:string);
begin
m_Panel:= TPanel.Create(AOwner);
inherited Create( false );
end;destructor TReceiveFile.Destroy;
begin
m_Panel.Destroy;
inherited;
end;
end.
我把TReceiveFile改成TForm1也不行。
可以在其它方面想办法,比如,分多页,某页要显示时再创建
或者创建后设置好其它属性,最后设置parent
不用一开始的时候就生成1000个
for j := 1 to 40 do//开始创建 begin
tpl[j]:=Tpanel.Create(self);
tpl[j].Parent:=ScrollBox1;
tpl[j].Height:=30;
tpl[j].Width:=55;
tpl[j].ShowHint:=true;
tpl[j].BevelOuter:=bvnone;
if j mod n=0 then//控制换行
begin
tpl[j].Top:=i*33;
tpl[j].left:=tpl[j-1].left+58;
i:=i+1;
end
else if j mod n =1 then
begin
tpl[j].left:=1;
tpl[j].Top:=i*33;
end
else
begin
tpl[j].Top:=i*33;
tpl[j].left:=tpl[j-1].left+58; end;
2.你的客户给你提供的那个程序,不一定是全部显示的,有可能只是显示个图什么的,然后你在操作的时候程序才开始真正创建的,这个很难说,我只是猜测
3.多线程来实现,我没试过,如果确实可以提高效率,希望告之
//模块执行
procedure TMythread.Execute;
var
AreaCodeList,ErrorGuestNumList:Tstringlist;
i,AllGuestNum,bedNum:integer;
FGusetNumString,DFileName,tempStr:string;
begin
inherited;
coinitialize(nil);
AreaCodeList:=Tstringlist.Create;
ErrorGuestNumList:=Tstringlist.Create;
DataSet:=TADOQuery.Create(nil);
ConnectionMain:=TADOConnection.Create(nil);
ConnectionMain.ConnectionString:=TPublicFunction.GetConnectStr;
DataSet.Connection:=ConnectionMain;
ConnectionMain.LoginPrompt:=False;
.....
couninitialize;end
先谢过了。能详细点吗?这初始化对它的创建速度会有帮助吗?不过我觉得他对查询这一块可能有很大的作用,所以可以的话,想请你列详细点,这里只有数据库的连接。
Classes, sysutils,;type
TMyTh = class(TThread)
private
{ Private declarations }
protected
procedure Execute; override;
public
constructor Create(参数); virtual;
destructor Destroy; override;
end;implementationconstructor TMyTh.Create(参数);
begin
inherited Create(True);
Resume;
end;procedure TMyTh.Execute;
begin
while not Terminated do
begin
//在这里写你创建控件的代码
Sleep(50);
end;
end;destructor TMyTh.Destroy;
begin
inherited;
end;
然后就是你自己写代码调用这个线程了
不管怎么说,在这里还是要谢谢大家的支持的!
Panels:array[0..999] of TPanel
for i:=0 to 999 do
Panles[i]:=TPanle.Create(nil);
我试了下,是0.01秒。再加上全部设完Parent,也就0.6秒多
之所以要在其它过程中创建,是因为我想通过数据库查询来创建这些控件,查到不同的数据就得重新删除、创建。
这里有个一模一样的系统可以下:http://www.motolock.com/download.asp找到2007-01版门锁管理软件
就可以下来装了。
那CAD图纸、工控图上几万个元件就没法做了,TPanel可是有Handle的重量级窗口啊。正确的思路应该是根据数据自己绘制,把每个房间看作一个图元类,包含房间各种属性,
由一个“面板”(一般可以从 TCustomControl 继承)统一管理,重载 Paint 方法,
把“房间”绘制出来...建议看看TSimpleGraph,ExpressFlowChart,ExpressOrgChart这些控件是如何做的,
这些控件一次显示几百个图元根本毫不费力(注意我是说创建/显示图元,之前查数据库不要算进去)
我是得承认我很不着道了,呵呵~ 刚接触delphi不久,很多东西都没有想到。所以希望像你们这样的大虾拉一把啊。你说的这些对我来说很有难度,能详细的描述一下整个绘制过程吗?要是有个实例就更好了。^_^
TSimpleGraph的源码delphi自带吗?我在它的Demos里找不到啊?
--------
http://www.delphiarea.com/products/simplegraph/google:约有6,750项符合SimpleGraph的查询结果,以下是第1-10项 (搜索用时 0.19 秒)I服了U ...
1000个没有必要一次全部创建吧,应该是按层分组,在一个就是不用DELPHI的控件,自己用绘图函数进行绘制。
Adoquery查询到的数据集可以重复使用吗?例如我在button1的onclick事件中编写了Adoquery1的sql语句。那么我在button2里的onclick事件中能不能直接就这样调用:
For i=0 to Adoquery1.Recordcount-1 do
begin
...//对数据集的一些操作;
end;
我这样直接使用adoquery1的数据集的话,显示出来的不是在button1事件中的哪些数据,好奇怪。不知道怎样才能得到Adoquery1最后一次查询到的值?????