By: Sarina DuPont
Abstract: Learn how you can take your existing C++ code from other development environments such as Visual Studio and use it in projects and applications that run natively on both Windows and Mac using the FireMonkey application framework
Learn how you can take your existing C++ code from other development environments such as Visual Studio and use it in projects and applications that run natively on both Windows and Mac using the FireMonkey application framework. Learn more at: http://embt.co/VisualCtoMac
In this video, I am going to show you how you can take your existing C++ code from other development environments such as Visual Studio, and use it in projects and applications that run natively on both Windows and Mac through the FireMonkey Application Framework.
We are going to work with an existing Visual C++ project and consider the common strategy of separating business rules from the user interface, allowing us to very quickly take code over to a FireMonkey project within the Windows based RAD Studio IDE and provide the same application compiled natively and running on the Mac.
I have opened my sample application in Visual Studio. It’s a common Customer/Order/Product application that loads data into separate linked-lists via a button on-click event that we’ve defined and then works on them or displays them from there.
We have several classes contained in class declaration and definition files-
Customer.hpp/.cpp, Order.hpp/.cpp and Product.hpp/.cpp. Now these are included in the solution and are called from, but are not part of the user interface code.
So I am going to run this application under Visual C++ to show you what it looks like. Here you see a simple operation on these classes as the application loads and organizes the data for each customer record.
Now let’s open RAD Studio and create a new C++ FireMonkey HD Application and then go and save the project.
Next, I am going to drop a button and a listbox onto my form, resize those, and then go and save my project again.
Now I am going to select the Cpp and header files for each class set and copy them from my Visual Studio folder on my machineover to my C++Builder project folder.
Now, I just have to go and add my class files to my project by right-clicking my project and selecting to add to each of the files and then add the include files into my unit.
Next we have to comment out the MFC include header in each of the 3 cpp files.
Now we are going to go back to our Visual Studio, Visual C++ project and select the on-click event code, copy it, and then paste it into our on-click event in our C++Builder project. We are also going to change the CString to a String for C++Builder.
The last couple of steps I have to take involve taking my function that makes adding to Listbox a little cleaner between the 2 different environments and Copy it and Paste it into my form unit.
Now we just need to update the form name to my C++Builderform name, and then update the C string to String for C++Builder.
Now we are going to change the declaration and just uncomment out the code; and we are going to take it from the definition and use it as a private declaration in the form. I am going to save the project and hit run to run it under Windows.
So now I want to target Mac. I have gone through a couple of quick and easy steps of
connecting my Windows machine to my Mac so that I can select Mac as a my target platform. All I have to do is right-click on Target platforms, select add platform, choose Mac OS X and then hit Run....
So we have taken our existing C++ code from Visual Studio and used it in this FireMonkey C++Builder project, allowing us to target both Windows and Mac natively from one codebase.
We could also create applications with custom user interfaces through the use of FireMonkey vector based styles.
All I have to do is select a component, right-click it, change default style and load one of the included styles.
Here you see the same application with the custom UI running on Windows, and now we are going to switch the target platform to Mac, and here you see it running on the Mac.
With the power of FireMonkey, you can quickly build applications for Windows and Mac from one codebase.
Free 30-day trial! Develop for Windows, Mac, Android, iOS, devices and gadgets!
More social media choices:
C++Builder on Google+
@RADtools on Twitter
Server Response from: ETNASC04