Delphi:框架 TList 的问题
我遇到了一个问题,该界面由 TScrollBox 中的多个框架(通常为 25 个)组成。
有 2 个问题,我希望其中一个是另一个问题的结果...
背景:
当应用程序启动时,我创建 25 个帧,每个帧包含大约 1 个帧。 20 个控件,然后填充默认信息。然后,用户可以单击控件将搜索限制为信息子集,此时我可以释放并重新创建我的框架(因为搜索可能返回 <25 条记录)
问题:
如果我退出初始搜索后的应用程序大约需要5秒返回Delphi。在第二次搜索(并处理/重新创建帧)之后,大约需要花费时间。 20 秒)
虽然我可以重写应用程序以仅创建一次框架,但我想了解发生了什么。
这是我的创建例程:
procedure TMF.CreateFrame(i: Integer; var FrameBottom: Integer);
var
NewFrame: TSF;
begin
NewFrame := TSF.Create(Self);
NewFrame.Name := 'SF' + IntToStr(i);
if i = 0 then
NewSF.Top := 8
else
NewSF.Top := FrameBottom + 8;
FrameBottom := NewFrame.Top + NewFrame.Height;
NewFrame.Parent := ScrollBox1;
FrameList.Add(NewFrame);
end;
这是我的删除例程:
procedure TMF.ClearFrames;
var
i: Integer;
SF: TSF;
begin
for i := 0 to MF.FrameList.Count -1 do
begin
SF := FrameList[i];
SF.Free;
end;
FrameList.Clear;
end;
我缺少什么?
I'm having a problem with an interface that consists of a number of frames (normally 25) within a TScrollBox.
There are 2 problems, and I am hoping that one is a consequence of the other...
Background:
When the application starts up, I create 25 frames, each containing approx. 20 controls, which are then populated with the default information. The user can then click on a control to limit the search to a subset of information at which point I free and recreate my frames (as the search may return < 25 records)
The problem:
If I quit the application after the initial search then it takes approx. 5 seconds to return to Delphi. After the 2nd search (and dispose / recreate of frames) it takes approx. 20 seconds)
Whilst I could rewrite the application to only create the frames once, I would like to understand what is going on.
Here is my create routine:
procedure TMF.CreateFrame(i: Integer; var FrameBottom: Integer);
var
NewFrame: TSF;
begin
NewFrame := TSF.Create(Self);
NewFrame.Name := 'SF' + IntToStr(i);
if i = 0 then
NewSF.Top := 8
else
NewSF.Top := FrameBottom + 8;
FrameBottom := NewFrame.Top + NewFrame.Height;
NewFrame.Parent := ScrollBox1;
FrameList.Add(NewFrame);
end;
And here is my delete routine:
procedure TMF.ClearFrames;
var
i: Integer;
SF: TSF;
begin
for i := 0 to MF.FrameList.Count -1 do
begin
SF := FrameList[i];
SF.Free;
end;
FrameList.Clear;
end;
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
由于您通过释放正在创建的框架来控制其内存分配,因此无需在创建构造函数中提供 Self 作为所有者参数。传递 nil 来防止所有者尝试释放框架。
另外,不喜欢 ClearFrames 例程的外观。试试这个:
As you are taking control over the memory allocation of the Frames you are creating by Free'ing them, so there's no need to provide Self as the owner parameter in the create constructor. Pass nil instead to prevent the owner trying to free the frame.
Also, don't like the look of your ClearFrames routine. Try this instead:
如果您想知道为什么您的应用程序需要这么长时间才能完成某些操作,请尝试对其进行分析。尝试针对您的程序运行Sampling Profiler。该帮助文件解释了如何将分析限制为仅应用程序的特定部分,您可以使用它来仅获取清理或创建部分的采样结果。这应该会向您展示您实际花费大部分时间的地方,并消除大量的猜测。
If you want to know why your app is taking so long to do something, try profiling it. Try running Sampling Profiler against your program. The helpfile explains how to limit the profiling to only a specific section of your app, which you could use to only get sampling results on the clearing or creating parts. This should show you where you're actually spending most of your time and take a lot of the guesswork out of it.