简体   繁体   English

在Delphi XE5中使用TFDQuery执行SQL查询时如何避免沙漏鼠标光标

[英]How to avoid of hourglass mouse cursor when executing SQL query with TFDQuery in Delphi XE5

I have grid control on form and when current record change i need to load RTF stored in DB. 我在表格上有网格控件,当当前记录更改时,我需要加载存储在DB中的RTF。 It works fine in general, but when i switch records i can see changes of mouse cursor to hourglass and back to regular: 通常它可以正常工作,但是当我切换记录时,我可以看到鼠标光标更改为沙漏并恢复为常规:

function TComments.GetDocument(AID: integer; ADst: TStream):Boolean;
begin
  try
    SelectQuery.Close;
    SelectQuery.Params.Clear;
    SelectQuery.SQL.Text :=
      'SELECT Dokument from Kommentarer ' +
      'WHERE ID = :ID';
    SelectQuery.ParamByName('ID').AsInteger := AID;
    SelectQuery.Open;
    Result := SelectQuery.RecordCount > 0;
    if Result then
      (SelectQuery.Fields[0] as TBLOBField).SaveToStream(ADst);
  finally
    SelectQuery.Close;
  end;
end;

If i comment "SelectQuery.Open;" 如果我评论“ SelectQuery.Open;” then cursor doesn't switch. 则光标不会切换。 I supposed there should be option in TFDQuery (or connection), but i can't find anything. 我以为TFDQuery(或连接)中应该有选项,但是我什么也找不到。 Any help? 有什么帮助吗?

UPDATE. 更新。 As TLama suggested, i placed WaitCursor:TFDGUIxWaitCursor at my form (one place for app) and use it this way: 正如TLama所建议的,我将WaitCursor:TFDGUIxWaitCursor放置在我的表单(用于应用程序的一个位置)中,并以此方式使用它:

  StoredCursor := WaitCursor.ScreenCursor;
  WaitCursor.ScreenCursor := gcrNone;
  try
    // access DB with queries
  finally
    WaitCursor.ScreenCursor := StoredCursor;
  end;

UPDATE2: Two more ways to do it. UPDATE2:还有两种实现方法。

  1. Set TFDQuery.ResourceOptions.SilentMode=True (simplest way to disable hourglass cursor for specific queries, property name is bad, but according to doc it doesn't block any dialogs, only changes of cursor). 设置TFDQuery.ResourceOptions.SilentMode=True (为特定查询禁用沙漏光标的最简单方法,属性名称不好,但是根据doc,它不会阻止任何对话框,仅会更改光标)。
  2. Set global variable FADGUIxSilentMode=True from unit FireDAC.UI.Intf (not best, but probably simplest way to disable changes of cursor globally for FireDAC). 从单元FireDAC.UI.Intf设置全局变量FADGUIxSilentMode=True (不是最佳方法,但可能是为FireDAC全局禁用光标更改的最简单方法)。

This is covered in this FAQ set: this FAQthis FAQ

How can I turn off the SQL hourglass completely ? 如何完全关闭SQL沙漏?

a) To disable the wait cursor completely for an application, use TFDGUIxWaitCursor with Provider = 'Console'. a)要完全禁用应用程序的等待光标,请使用带有Provider ='Console'的TFDGUIxWaitCursor The 'Console' provider contains an empty wait cursor implementation and the wait cursor will no longer be shown by FireDAC. “控制台”提供程序包含空的等待光标实现,并且FireDAC将不再显示等待光标。 If a mouse cursor is still changing, then check that only FireDAC.ConsoleUI.Wait unit is included into your application and FireDAC.VCLUI.Wait and FireDAC.FMXUI.Wait are not included. 如果鼠标光标仍在变化,则检查您的应用程序中是否仅包含FireDAC.ConsoleUI.Wait单元,并且不包含FireDAC.VCLUI.Wait和FireDAC.FMXUI.Wait。 Note that you will not have the ability to turn the wait cursor on again. 请注意,您将无法再次打开等待光标。

b) To disable the wait cursor, but to have the ability to enable it again later, use code like the following: b)要禁用等待游标,但要稍后再启用它,请使用如下代码:

 FDWaitCursor1.ScreenCursor := gcrNone; 

or 要么

 FDManager.ResourceOptions.SilentMode := True; 

c) To disable the wait cursor and FireDAC dialogs, but to have the ability to enable them again later, set the FDManager.SilentMode property to True . c)要禁用等待光标和FireDAC对话框,但又能够稍后再次启用它们,请将FDManager.SilentMode属性设置为True This will disable all wait cursors and FireDAC dialogs, including: 这将禁用所有等待光标和FireDAC对话框,包括:

  • The error dialog 错误对话框
  • Async execution dialog 异步执行对话框
  • Login dialog 登录对话框
  • Script progress dialog 脚本进度对话框

Setting ResourceOptions.SilentMode to True disables only wait cursors. ResourceOptions.SilentMode设置为True将仅禁用等待游标。

Since you want to turn off that cursor only for that query execution, use the option b and wrap your code with something like this: 由于您只想在执行查询时关闭该游标,因此请使用选项b并使用以下代码包装代码:

var
  OldCursor: TFDGUIxScreenCursor;
begin
  OldCursor := FDWaitCursor1.ScreenCursor;
  FDWaitCursor1.ScreenCursor := gcrNone;
  try
    // your code goes here
  finally
    FDWaitCursor1.ScreenCursor := OldCursor;
  end;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM