“正在处理,请稍候”屏幕有螺纹?

发布于 2024-08-18 06:17:36 字数 422 浏览 3 评论 0原文

也许,这对你来说很容易,但我正在努力开发一个项目(出于教育目的),该项目使用 TADSISearch 组件查询 adsi,持续了几天。当 TADSISearch 搜索 Active Directory 时,我试图在 Form2 上显示“正在工作,请稍候...”闪屏,其中包含一个男工动画 gif。虽然我根据自己的想法尝试了所有的可能性,但我没有成功。我尝试在线程中使用 TADSISearch,但线程在 ADSIsearch 完成之前终止。我认为 TADSISearch 不是线程安全的。你怎么认为?另外,我创建了 Form2 并使用线程来更新它的另一种方法,但动画 gif 停止了,而主窗体已经进行了 adsi 搜索。对于这些你有什么想说的吗?我怎样才能在 ADSISearch 工作时制作一个请等待屏幕并保持主表单响应。 Application.ProcessMessages 或计时器也不是一种方法。非常感谢您的阅读和回答。

Perhaps, it is very easy for you, but I am hard working on a project (for educational purposes) that is querying adsi with TADSISearch component, for several days. I'm trying to show a 'Working, Please wait..' splash screen with a man worker animated gif on Form2 while TADSISearch is searching the Active Directory. Although i tried every possibilities according to me, but i couldn't succeed. I tried to use TADSISearch in a thread, but thread is terminating before ADSIsearch finishes. I think TADSISearch is not thread safe. What do you think? Also, another way that I created Form2 and used a thread for updating it but the animated gif is stopping while main form gone adsi searching. What can you say about these? How can i make a please wait screen while ADSISearch is working and keep main form responding. Application.ProcessMessages or timer is not a way too. Thanks a lot for reading and answers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等待我真够勒 2024-08-25 06:17:36

图形用户界面应由主线程更新。您应该将搜索代码放入单独的线程中,当搜索器线程工作时,您的主线程可以显示动画以及“请稍候”消息。

当通过任何可用的同步技术完成搜索时,您的搜索器线程可以通知主线程。最简单的方法是在线程类中定义一个方法来停止用户界面中的动画,并将该方法传递给搜索器线程的 Execute 方法末尾的 Synchronize。

您的搜索线程代码将如下所示:

type
  TMyThread = class(TThread)
  private
    procedure NotifyEndOfThread;
  protected
    procedure Execute; override;
  end;

implementation

uses MainFormUnit;

procedure TMyThread.NotifyEndOfThread;
begin
  MainForm.ShowAnimation := False;
end;

procedure TMyThread.Execute;
begin
  try
    {Add your search code here}
  finally
    Synchronize(NotifyEndOfThread);
  end;
end;

您的主线程代码将如下所示:

TMainForm = class(TForm)
...
private 
  FShowAnimation : Boolean;
  procedure SetShowAnimation(Value: Boolean);
public
  property ShowAnimation : Boolean read FShowAnimation write SetShowAnimation;
end;

procedure TMainForm.SetShowAnimation(Value: Boolean);
begin
  FShowAnimation := Value;
  if FShowAnimation then
    {Add animation code here}
  else
    {Stop animation}
end;

The graphical user interface should be updated by the main thread. You should put your search code into a separate thread, and while the searcher thread is working, your main thread can show the animation along with "Please wait" message.

Your searcher thread can notify the main thread when search is done by any of the available synchronization techniques. The simplest one is to define a method in your thread class which stops the animation in user interface, and pass that method to Synchronize at the end of Execute method of your searcher thread.

Your searcher thread code will be something like this:

type
  TMyThread = class(TThread)
  private
    procedure NotifyEndOfThread;
  protected
    procedure Execute; override;
  end;

implementation

uses MainFormUnit;

procedure TMyThread.NotifyEndOfThread;
begin
  MainForm.ShowAnimation := False;
end;

procedure TMyThread.Execute;
begin
  try
    {Add your search code here}
  finally
    Synchronize(NotifyEndOfThread);
  end;
end;

And your main thread's code will be like this:

TMainForm = class(TForm)
...
private 
  FShowAnimation : Boolean;
  procedure SetShowAnimation(Value: Boolean);
public
  property ShowAnimation : Boolean read FShowAnimation write SetShowAnimation;
end;

procedure TMainForm.SetShowAnimation(Value: Boolean);
begin
  FShowAnimation := Value;
  if FShowAnimation then
    {Add animation code here}
  else
    {Stop animation}
end;
二智少女 2024-08-25 06:17:36

也许你可以尝试这个:

Threaded Splashscreen for Delphi
http://cc.embarcadero.com/Item/20139

我在触摸屏上使用它/终端应用程序(瘦客户端、Wifi、RemObjects 等),效果很好!
还得到了一个 gif 动画。

Maybe you can try this:

Threaded Splashscreen for Delphi
http://cc.embarcadero.com/Item/20139

I use this on a touchscreen/terminal application (thin client, Wifi, RemObjects, etc) and it works nice!
Also got an animated gif working.

掩于岁月 2024-08-25 06:17:36

线程如何在搜索完成之前终止?如果搜索是在线程中执行的,并且您只有一个线程实例,那么它应该可以工作。

How can the thread terminate before the search is finished? If the search is executed in the thread and you have only one instance of the thread it should work.

就是爱搞怪 2024-08-25 06:17:36

你能不能只

f := TMyWaitForm.Create(self);
try
   f.Show();
   ...start the TADSISearch...
finally
   FreeAndNil(f);
end;

在 TMyWaitForm(它会自动显示)上放置一个动画 GIF?

在我的网络创建程序中构建网站时,我有一个进度表,这就像一个魅力。

您甚至可以考虑在等待表单上显示一些状态信息(如果 TADSISearch 组件/软件具有可以分配的回调函数或事件)。

显示一个运行时钟,显示该过程所花费的时间,也是一个不错的选择。

Can you not just do a

f := TMyWaitForm.Create(self);
try
   f.Show();
   ...start the TADSISearch...
finally
   FreeAndNil(f);
end;

Putting an animated GIF on the TMyWaitForm (which displays itself) ?

I have a progress form when building websites in my web creation program, and this works like a charm.

You even may consider showing some state information on the wait form (if the TADSISearch component/software has a call back function or event which can be assigned).

Displaying a running clock showing the amount of time the process is taking, is also a nice touch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文