有人可以澄清Delphi FMX 10.3.1中的游标如何工作吗?我有一个冗长的动作,我希望应用程序的光标显示为 动作执行时的crHourglass。在以下代码中,我介绍了3个用于将光标设置为crHourglass的选项。
procedure TFormMain.actionFindExactMatchesExecute(Sender: TObject);
const
CCursorOption= 2;
var
IterationContextHits: TIterationContextHits;
begin
PanelResults.SendToBack;
PanelProgress.BringToFront;
case CCursorOption of
0: Self.Cursor:= crHourglass;
1: ButtonFindExactMatches.Cursor:= crHourglass;
2: CursorManager.SetCursor(crHourglass);
end;
{Create TIterationContextHits object to hold progress variables:}
IterationContextHits:= TIterationContextHits.Create;
try
{Lengthy code that searches multiple files for string matches}
{Report result of operation:}
ShowMessage('Number of matches found: ' + IntToStr(FHitCount));
{Update GUI:}
DataToControls;
PanelResults.BringToFront;
finally
IterationContextHits.Free;
case CCursorOption of
0: Self.Cursor:= crDefault;
1: ButtonFindExactMatches.Cursor:= crDefault;
2: CursorManager.RestorePrevCursor;
end;
end;
end;
在第一个选项中,我将MainForm的Cursor属性设置为crHourGlass,以期在执行过程中 应用程序将显示InheritedCursor属性,该属性应在组件的z顺序堆栈中搜索所有 返回光标值不是crDefault的第一个组件的主窗体的方法。但这不起作用。
在第二个选项中,我设置了链接到操作的按钮的cursor属性。如果单击该按钮以启动操作, 光标更改起作用。但是,如果操作是从主菜单项启动的,则不会。
在第三个选项中,我使用编写的TCursorManager类的对象包装与平台相关的服务IFMXCursorService。 这通常有效,但并非总是如此。的代码是:
TCursorRecord= record
FCursor: TCursor;
FStartTime: integer;
end;
TCursorRecordarray= array of TCursorRecord;
TCursorManager= class
private
FCursorService: IFMXCursorService;
FCursorRecordStack: TCursorRecordarray;
FCursorRecordCount: integer;
protected
function getcursorTickCount: integer;
public
constructor Create;
destructor Destroy; override;
function getcursor: TCursor;
{Returns currently set cursor}
procedure SetCursor(Cursor: TCursor);
{Sets new cursor}
function RestorePrevCursor: TCursor;
{Restores cursor previously set using this object}
property Cursor: TCursor read getcursor write SetCursor;
property CursorTickCount: integer read getcursorTickCount;
end;
implementation
constructor TCursorManager.Create;
var
CurrCursorRecord: TCursorRecord;
begin
{Create platform-dependent cursor service:}
if TPlatformServices.Current.SupportsplatformService(IFMXCursorService) then
FCursorService:= TPlatformServices.Current.GetPlatformService(IFMXCursorService)
as IFMXCursorService;
{Create current cursor record:}
CurrCursorRecord.FCursor:= FCursorService.getcursor;
CurrCursorRecord.FStartTime:= GetTickCount;
{Put current cursor record onto CursorRecordStack:}
SetLength(FCursorRecordStack,8);
FCursorRecordCount:= 1;
FCursorRecordStack[0]:= CurrCursorRecord;
end;
function TCursorManager.RestorePrevCursor: TCursor;
var
PrevCursorRecord: TCursorRecord;
begin
if Assigned(FCursorService) then
begin
if FCursorRecordCount>0 then
begin
{Remove current cursor record from stack:}
FCursorRecordCount:= FCursorRecordCount - 1;
PrevCursorRecord:= FCursorRecordStack[FCursorRecordCount-1];
{Reduce size of stack array if possible:}
if FCursorRecordCount mod 8 = 0 then
SetLength(FCursorRecordStack,FCursorRecordCount);
{Update start time of new curr cursor:}
PrevCursorRecord.FStartTime:= GetTickCount;
{Set previous cursor in system:}
FCursorService.SetCursor(PrevCursorRecord.FCursor);
{Return prev cursor:}
Result:= PrevCursorRecord.FCursor;
end;
end;
end;
procedure TCursorManager.SetCursor(Cursor: TCursor);
var
NewCursorRecord: TCursorRecord;
begin
if Assigned(FCursorService) then
begin
{Set up new CursorRecord:}
NewCursorRecord.FCursor:= Cursor;
NewCursorRecord.FStartTime:= GetTickCount;
{Add new cursor record to stack:}
if FCursorRecordCount= Length(FCursorRecordStack) then
SetLength(FCursorRecordStack,FCursorRecordCount + 8);
Inc(FCursorRecordCount);
FCursorRecordStack[FCursorRecordCount-1]:= NewCursorRecord;
{Call system procedure to set cursor:}
FCursorService.SetCursor(Cursor);
end;
end;
实现我想要实现的目标的最简单方法是什么?