Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TGestureManager causes immediate exception when in runtime-created TFrame


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 5 - Last Post: May 3, 2016 8:03 AM Last Post By: Eli M
Free Dorfman

Posts: 139
Registered: 2/4/12
TGestureManager causes immediate exception when in runtime-created TFrame  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 1, 2016 4:30 PM
10 Seattle. FMX. Windows 10.

Ok, So I've settled on a one-Form-only approach for my mobile app.

I've started rebuilding the app yet again. And, immediately another issue:

TGestureManager causes immediate exception when dynamically creating its parent (owner) TFrame (in Windows).
**EDIT** (not at my development machine) Might not be at creation. Might be at show. No TFrameStand or anything like that, though. Just a form with a TLayout & parenting the TFrame to MainForm.Layout1. Might be when Parent is set.

So I built a TINY test app. All I have is a MainForm:
type
  TForm1 = class(TForm)
    Button1: TButton;
    Layout1: TLayout;
    procedure Button1Click(Sender: TObject);
  end;
:
procedure TForm1.Button1Click(Sender: TObject);
var
  F: TTestFrame;
begin
F := TTestFrame.Create(Application);
F.Parent := Layout1;
end;


and a TestFrame:
type
  TgwfTestFrame = class(TFrame)
    Rectangle1: TRectangle;
    Rectangle2: TRectangle;
    GestureManager1: TGestureManager;
    procedure Rectangle2Gesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
  end;
:
procedure TgwfTestFrame.Rectangle2Gesture(Sender: TObject; const EventInfo: TGestureEventInfo; var Handled: Boolean);
var
  S: string;
begin
GestureToIdent(EventInfo.GestureID,S);
ShowMessage(S);
end;


it's FMX:
  object Rectangle2: TRectangle
    Touch.GestureManager = GestureManager1
    OnGesture = Rectangle2Gesture
  end
  object GestureManager1: TGestureManager
    GestureData = <
      item
        Control = Rectangle2
        Collection = <
          item
            GestureID = sgiLeft
          end>
      end>
  end


Couldn't be any simpler, right?

When I MSWINDOWS run this, as soon as I click Button1, I get EGestureException: "Unable to enable or disable IRealTimeStylus. The clear disable flag is set and all operations now require physical access"

Which was freaking me out. Yet another no-go design approach?!!?

But: If I ANDROID run this, everything seems fine.

So:
(1) What gives?

(2) Should I just kill gestures via {$IFDEF MSWINDOWS} which would certainly be a pain, app-wide.
Perhaps calling GestureManager1.Free; in the TTestFrame's OnCreate? Oh, right, no OnCreate.
I spent a month setting up an app framework that had the "main form" triggering the following events within its child frames. Everything there is like 98% perfect. But - for a variety of reasons - I am, yet again, rebuilding this app (call it Attempt Four).
    procedure OnParentFormShow; virtual;
    procedure OnFrameFirstShow; virtual;
    procedure OnFrameLaterShow; virtual;
    procedure OnFrameRearrange; virtual;
    procedure OnFrameRedisplay; virtual;
    procedure OnFrameRepalette; virtual;
    procedure OnFrameHide;      virtual;
    procedure OnFrameClose;     virtual;
    procedure OnFrameDestroy;   virtual;

I have given this (using my TjxFrame class) up (at least for the moment as I rebuild the app, planning on using TFrameStand) but now even the base TFrame class isn't working with gestures and frames.

(3) Is this only problematic for MSWINDOWS? Or am I going to have issues when I get to IOS or MACOS?

(4) Shouldn't I be able to have multiple TGestureManager instances throughout an app? Are they all [or just the one - if that's the way to go] supposed to be on the MainForm? If so, am I going to have to set all the GestureManager & Gestures properties at runtime?

I did some web research and found a couple people asking about the very exception message listed above. But no solutions or answers given.

I feel like I might just be overlooking (woefully ignorant of) something simple here - but I just don't get it.

Thanks.

##### -- added 2016-05-02 12:20 -- #####

I've filed a report with QC: https://quality.embarcadero.com/browse/RSP-14734

This issue can be (as Dave Nottage mentions below) encountered in a variety of ways. I've listed a 2nd one in my QC report

##### --
Eli M

Posts: 1,346
Registered: 11/9/13
Re: TGestureManager causes immediate exception when in runtime-created TFrame  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 1, 2016 6:43 PM   in response to: Free Dorfman in response to: Free Dorfman
http://docwiki.embarcadero.com/RADStudio/Seattle/en/FireMonkey_Platform_Services

This might check if that device service exists on Windows:
TPlatformServices.Current.SupportsPlatformService()

What are you using gestures for? It might be an issue with TFrames+Gestures. I just use OnClick and OnMouseMove etc. like a normal Windows app.
Free Dorfman

Posts: 139
Registered: 2/4/12
Re: TGestureManager causes immediate exception when in runtime-created TFrame  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 1, 2016 10:58 PM   in response to: Eli M in response to: Eli M
Eli M wrote:
http://docwiki.embarcadero.com/RADStudio/Seattle/en/FireMonkey_Platform_Services

This might check if that device service exists on Windows:
TPlatformServices.Current.SupportsPlatformService()

What are you using gestures for? It might be an issue with TFrames+Gestures. I just use OnClick and OnMouseMove etc. like a normal Windows app.

Eli,

I checked that page out (again). Thanks. The weird thing is I'm only having an issue under Windows. A problem with Gestures+TFrames you suggest? in a tool where those are [seemingly] absolutely central players in mobile development? That would be tragic!

I really appreciate your thoughts and help on all this. This first app of mine (a framework for some additional ones which I assume will follow this one fairly quickly - although this one's taking "fo-evuh") is a really simple (I believe) word game app.

Think: (I'm speaking from a user's perspective here, not a developer's)

*Main Screen - list of Packages (vertically scrolling big buttons with text and category and progress indicators on 'em). Click one.

*Package Screen - list of Puzzles (vertically scrolling blah blah blah - same as above). Click one.

*Puzzle Screen - series of Items (all visible on screen, resized in code for any deployment/orientation).

*Each Item - series of Tiles.

That's the gist of it.

*Plus a menu that slides in. (Gestures. Left on one control. Right and Left on another. Simple!??)

*And the Menu - Settings, How To, About, etc Buttons.

The way I've got it now (again - Phase Four - although the design stuff I'm talking about here was introduced in Phase Three) is a TApp class (TObject) that contains PackageBtns, PuzzleBtns, Items (and each Item, Tiles).

These Packages, Puzzles, etc (and their buttons) are created up front, for the life of the app (after determining - from the DB - NumberPackages, MaxPuzzlesPerPackage, MaxItemsPerPuzzle, MaxTilesPerItem) -- so I've got a lot of up front stuff to do.

They're created once and Rearranged (size, position), Redisplayed (data), and Repaletted (color, font) as needed.

This is not a business-y app. I've been writing business-y stuff since the late 80s. And - until about a year ago - had been as far forward as D6. Yes, the (c) 2001 D6.

I gave up fairly early on using TButton. I have created a TjxBtn that I can make big, give it perfect corners, put a stretch-or-shrink-with-the-screen "label" on it. It's a TRectangle composed of one TRectangle for each side, lest the corners be ugly - one of the first harsh eye openings of this journey. (Something about pen tips under GPL(?) for different destinations.)

I am - so far very successfully - using no additional forms or controls for Windows vs Android. I really like this approach. [Sometimes I feel Delphi is overkill and I could/should be going Lazarus or something totally non-visual.]

The whole OSX (which I really don't care too much about) and IOS deployments I have been putting off. As soon as this Phase Four restructuring is working, Phase Five will be getting what I've got onto IOS (by way of OSX).

I'm expecting some eye openers there as well.

Back to the gestures question, though. I am building a simple yet flexible framework from which to develop and deploy a series of puzzle-y apps. I want to "sex them up" a bit. With animations and graphics and transitions and - yes - gestures.

I'm about to see if there's ANY way I can get a TGestureManager to work - at all - on a TFrame. And - if not - to try and determine where the Exception actually pops.

Also - I am torn about possibly writing some kludge to simply kill the gestures (GestureManager1.Free will be tricky as it's a TFrame without OnCreate; and - even OnCreate might not work - might need to override Loaded - or some such) under windows as they seem to work on android. But I'm concerned that kludge only leaves me open to more possible problems with IOS than I might otherwise have.

Also - part of the reason I did my Phase Three rewrite in the first place (although I did some significant restructuring as well) was simply to get rid of a bunch of kludge I had already written regarding when items should be sized, made visible, have their fonts set, and so on relative to their frame's creation, showing, hiding, re-orienting, etc (especially the first time they're seen in the life of the app).

It seemed like I should - all at once - (a) fix my splash problem; (b) employ TFrameStand for "better timing" and help with stuff like animations and transitions - but also to get me down to JUST ONE FORM; (c) eliminate much of the kludge.

I've never been a fan of kludge-y coding. Maybe I should just accept it here [mobile world / multi-device development] and move on??! But - as I've said a couple of times - I'm trying to build a very solid foundation here. And I don't want to do a bunch of shortcuts and workarounds and good-enoughs that will eventually, inevitably, undoubtedly, bite me in the ass as I re-use and expand on this foundation.

Thanks for the ramble,

-Free
Dave Nottage

Posts: 1,850
Registered: 1/7/00
Re: TGestureManager causes immediate exception when in runtime-created TFrame [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2016 12:28 AM   in response to: Free Dorfman in response to: Free Dorfman
Free Dorfman wrote:

A problem with Gestures+TFrames you suggest? in a tool where those are [seemingly] absolutely central players in
mobile development?

FWIW, I have been having the issue without using GestureManager, or Frames. (in an XE2 project)

You might be able to work around the problem by making a copy of FMX.Gestures.Win, place it in your project path and
modify the TWinGestureEngine.TRealTimeStylus.SetEnabled method, thus:


procedure TWinGestureEngine.TRealTimeStylus.SetEnabled(const Value: Boolean);
begin
  if Value <> FEnabled then
  begin
    FEnabled := Value;
    // Using True for the Silent parameter prevents an exception
    if not EnableStylus(FEnabled, True) then
      FEnabled := not Value;
  end;
end;
 


No guarantees that your app will continue to work as expected, however it should prevent the exception

--
Dave Nottage [TeamB]
Hint, tips and tricks at: http://www.delphiworlds.com/blog
Free Dorfman

Posts: 139
Registered: 2/4/12
Re: TGestureManager causes immediate exception when in runtime-created TFrame [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 2, 2016 12:33 PM   in response to: Dave Nottage in response to: Dave Nottage
Dave Nottage wrote:
FWIW, I have been having the issue without using GestureManager, or Frames. (in an XE2 project)

You might be able to work around the problem by making a copy of FMX.Gestures.Win, place it in your project path and
modify the TWinGestureEngine.TRealTimeStylus.SetEnabled method, thus:
--
Dave Nottage [TeamB]

Dave,

Thanks. Rather than that "hack" (and I mean that in a "nice workaround" way), I'm now placing the GestureManager on the MainForm and assigning the Touch.StandardGestures in code, following the creation of the TFrame:
procedure TForm1.Button1Click(Sender: TObject);
var
  F: TgwfTestFrame;
begin
F := TgwfTestFrame.Create(Application);
F.Parent := Layout1;
{$IFNDEF MSWINDOWS}
F.Rectangle2.Touch.GestureManager := GestureMgr;
F.Rectangle2.Touch.StandardGestures :=
  [TStandardGesture.sgLeft,TStandardGesture.sgRight,TStandardGesture.sgUp,TStandardGesture.sgDown];
{$ENDIF}
end;


So, with the MSWINDOWS check in there, I'm not generating any exceptions. Of course this also means no Gestures under windows. I don't care about this as I'm writing a mobile app.

Note that even with the TGestureManager being on the MainForm the original exception is still raised under windows.

I filed this as a QC issue (citing both scenarios): https://quality.embarcadero.com/browse/RSP-14734
Eli M

Posts: 1,346
Registered: 11/9/13
Re: TGestureManager causes immediate exception when in runtime-created TFrame  
Click to report abuse...   Click to reply to this thread Reply
  Posted: May 3, 2016 8:03 AM   in response to: Free Dorfman in response to: Free Dorfman
http://docwiki.embarcadero.com/Libraries/Berlin/en/FMX.MultiView.TMultiView

It handles the gestures for you.

Free Dorfman wrote:
*Plus a menu that slides in. (Gestures. Left on one control. Right and Left on another. Simple!??)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02