2

Even though it is not officially supported by Embarcadero there are many examples showing that you can include a FMX form in a VCL application e.g. MonkeyMixer and this SO question. However, when I create a test application with only one empty VCL form and one empty FMX form, I get two problems:

  1. There are two application icons in the task bar (apparently one for each instance of TApplication i.e. VCL and FMX)
  2. It crashes when I close the application (when it calls TStyleManager.UnInitialize in FMX.Forms.FinalizeForms).

How can I make this work?

I need this combination as we want our application to be native on Windows, Mac OS and iOS. Therefore on Windows it is a VCL application and the other OS's are FMX using the TMS native components. We have some large custom graphical components that are made for FMX, and they must also work on Windows.

Edit:

I see only two alternative solutions, and I like none of them:

  1. Use FMX on Windows too. I don't like the idea of styled components instead of native. Experienced users can easily tell the difference.
  2. Maintain to sets of our custom components: VCL and FMX editions. That will require some work, and also the graphical features of FMX are much better than VCL.
Community
  • 1
  • 1
Hans
  • 2,220
  • 13
  • 33
  • So is your question "Anyone having experience making this work?" Because my answer is no. I hope someone else can say yes. – Jerry Dodge Mar 03 '15 at 15:51
  • @JerryDodge: you are right, it is not really the question, so I edited it. – Hans Mar 03 '15 at 16:49
  • 1
    Even if you could get it to work with two empty forms, you would be fighting windmills with everything you build upon that. Not to mention how fragile your application would be in future versions of Delphi. Emb has documented that VCL and FMX are not compatible, they have no obligation to support any trickery you would use now to get it to work. If you *must* stick to native controls in Windows, why not create two projects with the thinnest possible UI you can imagine and rest of the code in common modules? Or take the supported route of FMX also in Windows? – Tom Brunberg Mar 03 '15 at 17:01
  • Indeed, a decision like this I would assume would break like crazy the moment you upgrade to a newer Delphi version. – Jerry Dodge Mar 03 '15 at 17:12
  • I totally agree with you and we have already implemented a MVVM structure in the code, but the question is about some of our visual components. They are large and complex, but they are still components and belong in the View. – Hans Mar 03 '15 at 17:23
  • Maybe I'm missing something, but if you modify your visal component to work in FMX on OSX and iOS, why would it not work in FMX on Windows? – Tom Brunberg Mar 03 '15 at 17:38
  • As to your edit: Do experienced Windows users actually care? `graphical features of FMX are better` sounds like an opportunity for marketing. But I'm not going to argue with you, you know your users and their mindset much better. You just have to decide what to do. – Tom Brunberg Mar 03 '15 at 17:53
  • @TomBrunberg Nothing to argue about, I see 3 possible solution and first try to make the first priority work. If there is no solution to this, I will have to consider the pros and cons for the other too. My experience is that Mac user are sensitive to native behavior, but our application was always VCL/LCL until now, so I don't know how sensitive Windows users are. – Hans Mar 03 '15 at 19:11
  • I've needed to host an FMX app inside a VCL app for display and training purposes. The FMX app is really an Android target and the VCL a Windows 'demonstrator'. The FMX hosting is done using TFireMonkeyContainer hosting the FMX main form. Yes it's got slight wrinkles but it works ok and I'm sure we'll find a way to improve things. – Brian Frost Mar 05 '15 at 14:51
  • @BrianFrost Did you try in Delphi XE7? It seems like it changed recently that you can no longer have a VCL form and a FMX form in the same application. – Hans Mar 05 '15 at 15:18
  • @Hans: Yes, it is XE7. My FMX main form is created at runtime and has visibility of only FMX.Forms. It is then passed to TFireMonkeyContainer and is destroyed by it when the VCL app closes. – Brian Frost Mar 06 '15 at 16:02
  • @BrianFrost: It works, thank you. Give it as an answer and I will mark as the answer. – Hans Mar 06 '15 at 16:51

1 Answers1

2

I've needed to host an FMX app inside a VCL app for display and training purposes. The FMX app is really an Android target and the VCL a Windows 'demonstrator'. The FMX hosting is done using TFireMonkeyContainer hosting the FMX main form. Yes it's got slight wrinkles but it works ok and I'm sure we'll find a way to improve things.

My FMX main form is created at runtime and has visibility of only FMX.Forms. It is then passed to TFireMonkeyContainer and is destroyed by it when the VCL app closes.

Brian Frost
  • 13,334
  • 11
  • 80
  • 154
  • Using the dedicated events in TFireMonkeyContainer to create and free the FMX form did the trick. All my other attempts to create and free the FMX form manually in different places failed. Only TFireMonkeyContainer could do it right :-) – Hans Mar 09 '15 at 10:03
  • There are still some issues with TFireMonkeyContainer though, I've seen the edit cursor vanish when an FMX TEdit or TMemo has focus. This seems to be a known issue though. – Brian Frost Mar 10 '15 at 11:16