Friday, December 6, 2019

MVP of the Year / German candidates.

Hi!

The election of the Embarcadero MVP of the year has started.

If you like my stuff please vote for me!

Here is the link to Olaf Monien's homepage (Developer Experts) if you like to vote:


This is only for German MVP's every region has it's own system.

Thursday, November 21, 2019

Delphi 10.3.3 and Android 64

Finally here are the news about Delphi 10.3.3.


No more mimimi about not be able to build Android 64 with Delphi.

Also iOS 13 with Dark-Mode support.

If you want to get the information what mode the User has selected, just modify the FMX.Platform.iOS (Copy file to your project directory)

and Copy

const
  UIUserInterfaceStyleUnsepcified = 0;
  UIUserInterfaceStyleLight = 1;
  UIUserInterfaceStyleDark = 2;

and 

function GetUserInterfaceStyle: UIUserInterfaceStyle;

to the Interface section!

Also a ready to use Linux-Docker image on Docker-Hub.

If you have the Enterprise Version and want to Build your App with FMXLinux you can provide empty implementations for some System units.
Of course only necessary if you are using this stuff in your app.

// Empty Implementations
System.Linux.Notification.pas 
System.Linux.Sensors.pas
// Add IFDEF Linux64
System.Notification.pas
System.Sensors.Components.pas
System.Sensors.pas


Tuesday, November 12, 2019

#CodeRage2019 - Fluent Creation of controls at runtime!

The Embarcadero CodeRage2019 (worldwide)!



Of course, I had to provide a session to this event with one of my beloved topics:

My FluentCreator!

(Part of my FDK - The Firemonkey Development Kit)

The #CodeRage2019 event should only contain tutorials of 5 to 10 minutes of playtime. So I will provide a more detailed session in the next days on my YouTube-Channel 



(Btw. This is my first tutorial in the English language - I will provide German subtitles on my channel in the next days and if I find the time I will upload my older sessions with English subtitles as well)

Yes, this channel has not seen any new content for a long time, but I will provide more stuff in 2020.

The short version you can find here! 

If you want to submit a question to the Firemonkey Multi-Device Design Q&A session at 14.Nov.2019, please click here.

Here is the full list for the FMX-week. 

Please leave a comment or send me an email if you like to see another topic of Firemonkey development.

Thursday, October 31, 2019

How long does it take to develop a "complete" MVVM framework for Delphi?

This is a really good question. (Btw. what is complete? We all know a framework is never complete)

Maybe you have a different question in mind... Is it worth to spend x man-days trying to develop it? 

Spoiler - Yes!

If I had not believed that it was possible, I would never have started another attempt. 

If you have not read my other posts about MVVM - yes I've been trying this since 2015. (Of course not all the time).

Is this my last attempt? - I hope so - or better, I hope that this is the final version that fulfills all my wishes - as well as yours  (one of which is to prove: Yes, with Delphi it is possible to develop a framework with the idea behind MVVM)  

Most of the time I had to spend on a better binding structure, studying the source of this unit... Oh boy, I have to refactor this code for better readability.

We all know the MVVM images with the three colored boxes and the fancy arrows labeled with reading, writing, binding, property changes, event or whatever. Everybody starts with this.

Then you google for tutorials or search at youtube. Yes, you will find some stuff, but if you dig deeper and deeper into MVVM you have to rethink about these videos. So many mistakes. (of course from my point of view).

On the surface, the MVVM-Pattern is just a guide on how to separate the visual parts from logic and put everything in a state to be able to perform unit tests. Is this so? 

Yes, but the devil is in the detail.

And everybody is doing it a little bit differently. Then you learn from this tutorials how to do "a" and by reading more and more "a" is suddenly an antipattern and everybody is blogging about "a" is bad you have to do it like "b". Sometimes it sounds like the discussions about using FreeAndNIL. (Please no comments on this topic) ;-)

Who holds the instance of a, who can create b and how to perform c? Using the approach from a tutorial or is there a better way? - is the better way still the "right" way? - and who decides this? Some experts or MS? What is an expert in MVVM? 

If you are in front of your screen staring at an empty unit in the IDE - I call this 

"The loneliness of development" 

you easily get overwhelmed from all the decisions you have to make. #AloneInTheDark Only if you are using the dark style!

My advice - talk to another developer. Perhaps she/he is not right or has a completely different idea or opinion - that does not matter. Take the feedback and do it your way, perhaps you can adjust your first idea with the feedback.  

And here I am - 3 months into the final version. (only in my spare time I do the MVVM development). It's working - and it is fast - and it is easy to use - and there is (nearly) no code in the View/Form - and most of the necessary (stock) visual controls are already working (no imposer necessary) - and you have to write less code you would expect - and I love the implementation. 

More than half the time is debugging time (so far). I did not use TDD this time, because I had no idea where to start with the tests. 

Good news:
- The implementation is working with FMX ( this was no question, wasn't it ) but also with VCL.
- I have a small team of developers for beta-testing.
- There will be two different versions. Of course as a Plugin to my FDK, but also a stand-alone Version.

The FMX Version is more advanced at this state and the VCL version will see "the light of release" a little bit later. The documentation is not existing at the moment and to show the benefits of the framework I have to do some youtube-videos - this is for sure. But not this year - perhaps you will see "something" at CodeRage 2019. (Nov 11. 2019). But this is not decided today.

To answer the question of the blogpost: 6 Month or 4 to get a beta and perhaps one more month for documentation and another one for videos. I will use the FDK installer, which is capable of doing user registration, updates, online-store, and invoices. (bug tracker is coming) Two months. So overall until everything is out including VCL - The final answer is one year.

I assume, that with the final framework, I will be able to create MVVM based Apps at least in half the time than before, just a little bit more than doing good old RAD-stuff, but everything testable. By combining this framework with my FDK you can build a multi-platform-app in weeks instead of a month. 

The future of App-development will be great.

PS.: The new version of the installer is using gnostice document studio for FMX. At forentage I told everybody that I not using this component by myself - this has changed. Thanx to my friend Girish Patil for the support.


Tuesday, October 15, 2019

FDK Version 2.0 Beta online!

Hello FDK fans!


Finally the new Version 2.0 is online. As always, you are able to order and download it with the setup application.

As we haven't done any updates is the last year, there will be a special offer:

If you're already an FDK-customer you can order an update of you Version 1.0 only for 29,95€. If you like to update to Version 2.0 (beta) there is a discount until 15.12.2019, so you get the update for only 199,- €. The normal price is 299,- € for the update.

If you are new to my FDK the prize for a new customer is 399,- €. If you like to order the FDK with an online lesson, just send me an EMail.


Greetings

Monday, October 7, 2019

MVVM for legacy Apps?

The most developer would not do this step. But what kind of refactoring you want to do?


Well, if your app is still pre-Unicode, you probably have more to think about than implementing an MVVM Pattern, isn't it? Let me take a look into my crystal ball:

One problem of your migration is: If you change one thing at one end, you break something at the other end. I assume you have no or only a few unit-tests. Your app is not testable, because all of your business logic's are in your forms and everything is using nearly every other unit? You have referenced all over the place and have not used one interface?

Welcome to the club.

Perhaps it is even worse and you're using (typed) Short-Strings as Var-Parameters everywhere?

So your migration is not a "one-shot changes everything for good". It's more like change a little bit here and there and hope for the best. I hate to say it, but I'm doing the same for many years. Starting with old components!

I have the source, but it is really to complicate to migrate every old stuff. (And why it is working) so the best way is to do an interface wrapper and if everything is still working, I can put this in a DLL compiled with the old Delphi and uses this DLL from Rio. Perhaps some time replace this with a new implementation.

So far so good. One problem is still in place, I'm not sure if really everything is still working, because I can only do some "human application tests". Wouldn't it be great if I had at least 10% unit-tests coverage of the main core stuff? How to accomplish that?

Here is the deal: Convert your app step by step to MVVM. Normally it's not so complicated, because in 99,9% every Form is one View, every Frame is one View and normally you would end up only with a 1:1 relation. Do you need a Model? In a best-case scenario, yes!

A part of my #DMVVM framework would be related to doing this kind of "easy" migration. But there are still some problems: No real RTTI and generics in D2007. If the framework can be compiled with D2007 - possible not, but perhaps the D2007 stuff could be in a DLL.

Stay tuned...

Tuesday, October 1, 2019

FMX-Styles Update

Prior posts about FMX Styles!

Here a little update:

I changed all the SysColors to $FF000001 and all Colors to $FF000100 then exported a list to see if these color values are used elsewhere. And yes they are...
Not the colors from the Colors tree, but from the SysColors-Tree. So I change all "not found" colors to 000101,000102,000103,000104... and so on.

Then I compared the to exports:



So here is an update of the used SysColors:


EditStyle Selection-BrushColor and other selections using the clHighlight Color and for Focus. Like in Grids.


Funny the Grid-Lines are using clBtnFace.

The ListView is perhaps (not in the Styleviewer) using the clWindow Color for Background and ItemBackground (not confirmed). And the TEllipse is using clBtnText for Fill-Color - strange - also not confirmed.

That's it.

Monday, September 30, 2019

Did you try to design an FMX-Style?

Do you like the styles that are included or downloadable from getit?

Perhaps you have tried to design your own style with the Bitmap-Style-Designer. 

Did it work for you?

Perhaps the problem is, that the Style-Designer is more on the VCL side... Let's take a look. First create a new "Modern Windows Style". There are two color entries (Colors and SysColors) Let's set all Colors to green (Except three that are really needed) and all SysColors to Cyan except the only two that are used from here. Then it looks like this:


If you change a color like "Window" (I did orange) the color value is not indexed to all components, the color is copied to the components. Like:



Perhaps it's a feature to be able to change this color...

Hmm, and where did I already set the font- /back-colors to white/black? 



OK, some colors are not set over color values, because the color is rendered from the bitmap.

Take a look at the edits.


Wow the Edit background is lighter, but how to set background color? It's set by this bitmap. The background of this image-part has just a  not 100% transparent Alphacolor. 



The Run-Test-Button is helpful, because you can change something and check the results... Like this:

That is colorful - but where are all their colors from? Not from the color settings - too bad! These colors are set under Listbox (but not all).

Listbox Header - two different colors - but not set with the header:


If you think this is perhaps set with PlainHeader, no PlainHeader is the Teal-Group Header and of course always the Font-Color not the Color entry. It would be to easy just set PlainHeader.Text.Color := clBlack. and this property will also set the Fontcolor. The blue GroupHeader is set by GroupHeader.Text.Font.Color and BottomDetail.Text is also set with BottomDetail.Text- that's fine. DetailText is correct. PlainItem is not PlainItem. DetailText2 is not Detail it is the ItemText5 and Detail from this is set with BasicText2. Get confused?
Scroll down there is a single entry for ListBoxHeaderLabel - this is the other ListBoxHeader. The other (Black ListBoxHeader) is not set under Listbox, because this is a ToolLabel and set under ToolLabel. This is the same for the ListItemButton.Text.


And this colors?
Purple backgrounds are set with - roll drum - clBtnFace under Syscolors. This is also the color for the Splitter.


The yellow border is set under Colors - Border.
But where to set the Arc and the CornerButton? This is not set by the Bitmap...


Here comes the best part. The CornerButton is set with a gradient and the gradient has two colors.
And no - the color is not set over Color and of course not set over Font.Color the Color value hast Du be set over PARAMS! But don't forget to switch From ARGB to ABGR (Blue and Red color switch places)

This is not a complete list of problems with the colors and I did not test this colors with a real world app so far. I did not test this on all platforms. I will try to implement some kind of color - converter - post-setup for the styles... 

So stay tuned.

PS.: Here is a litte update!

Wednesday, September 18, 2019

MVVM PropertyChanged is not Component related!

What? I use many components!

ok - let's assume you have a Button on the Form and the button is labeled "Save". How do you want to handle this button? 

1.) You can use this button like a web designer and after the button is pressed you can show up some hints: "Password missing", "Email missing" or whatever. So the user can press <Save> and directly see what is missing.
2.) You can disable then Button and enable it if every field is filled as you expect.  This is kind of a guessing game or you must have some remarks like "*" for fields that have to be filled. The drawback is, sometimes you have to search the view for the little missing "I agree" checkbox.

In a few situations, I like (1), but in most cases, I use (2).

So how to handle this in the ViewModel?  PropertyChange('DisableButton')?

No, this is wrong.

You have a property at the ViewModel like:
Property CanSave : boolean read fCanSave write SetCanSave;
In the setter you can fire PropertyChange('CanSave') and every component that has to change something could be informed by this event. When a component got his PropertyChanged call it can ask the ViewModel.

SaveBTN.Enabled := fViewModel.CanSave;

ok. 

This is the same stupid thing, already mentioned in my last post. I know "you" can bind a button to an ICommand, but that is not my idea. My PropertyChange would also include the boolean so the component or better the binder can set the value directly. Of course any boolean field could be bound directly, but what if I must do a little bit more? 

One of many ways to handle this is a simple procedure:

Binding.Bind('CanSave',Procedure(aEvent:TPropertyChangedEvent )
  begin
    if aEvent.ParamCount = 1 then
      begin
        if aEvent.Args[0].AsBoolean
          then StateImage.Bitmap.Assign(YesIMG)
          else StateImage.Bitmap.Assign(NoIMG);
      end; 
  end);

I use this approach for everything that is not working out of the box. (Implementation is currently still under consideration in some parts)

And this is the main thing. The ViewModel knows the Model (in most cases) and the View knows the ViewModel. But the Model does not know the ViewModel and the ViewModel does not know then View. Perhaps the designer of the View is a different developer than the ViewModel.

Perhaps the Model has already two new fields and the ViewModel has only implemented one of these fields, but the View isn't changed at all. Everything should work fine because there is not 1:1 relation. What should the binder do? In debug-mode it would be nice if the binder throws an exception "Property not found" and in release mode? It depends on the settings. I like the idea that every Visual Component is set to Visible := false; if the necessary property is still missing in the ViewModel, but this is up to you. How do you handle incompatibilities between the View and the ViewModel? Feel free to leave a comment!

Now, how about the Unittests?

The Model is simple, just write your tests. Test for the View? Perhaps. But besides your most important Model-Tests you also want to test your ViewModel. 

Testing your ViewModel without a View must be possible, so your Test class slips into the role of the View. By subscribing to the 'CanSave' property change - for example - and filling all the fields (or not for the negative test), the test class can check if everything works as expected.

How can you test complicated behavior like the user interaction with a Grid?

Well, this may be the topic of one of my next blog posts about my #DMVVM framework.

So stay tuned.


Sunday, September 15, 2019

MVVM and mobil app development.

A big part of the MVVM Pattern is separation and binding. I don't know how you are developing your mobile apps, but in my apps, many parts, I mean more than 80%, are created "on the fly" at runtime. Sometimes the elements would be created from the content of a database, sometimes from a REST(full) Webservice and sometimes from a config or user settings.

So here comes the funny part: Imagine controls have to be created from a database. From a ButtonClick on the View, the ViewModel calls the Model. The Model loads all the necessary information and hast to provide this information to the ViewModel. So far so good.

If you take a closer look, every component -  like a TEdit - is some kind of View. Views are created by the composition-root, perhaps from an event of the navigation-service, perhaps from a ViewLocator or in case of e.g. Messagedialogs, from a dialog-service. 

In this case, the ViewModel is created with a component-service to create a component from a predefined collection. Wouldn't it be great, If we already had a service like this? Yes we have. My FluentCreator could be called by this service and is able to provide an easy way to create predefined  - even complex - view-structures like I've demonstrated in my scale-able calendar component. 

But where is the target? The target is a container (TLayout/ListBox) on the View, but we don't have a View-reference in our ViewModel. Conclusion the View must call the component-creation-service. Not a big deal, we could create the View with this service. But how to pass all the information from the Model to the ViewModel to the View to the component-service and keep in mind, the Viewmodul has to be testable and if possible the service, too.

One problem, the possibilities of component creation are endless. We could fire a PropertyChange with some kind of string. E.g. "Create Edit_ID parent Listbox1" we could find the Listbox1 and we could create a TEdit_ID from our lookup list in our component-service. But our ViewModel should not know "Listbox1".

The next problem is the binding. How could we create the binding to our ViewModel? There aren't any properties to bind to. We also have to create a dynamic receiver for the created components and I'm sure we have to provide some kind of database connection to the receiver.

It looks like our component-service as three parts: One for the View, one for the ViewModel and one for the Model... 

To implement an easy to use MVVM framework is not trivial, but doing everything at runtime is a step forward. Of course, there will be a way, but finding the "best" way is the tricky part.

Think about it, I would love to read your ideas on this topic.

PS.: The dynamic creation stuff is probably not mobile related, but from my point of view Desktop apps are more static these days...


Friday, September 13, 2019

VCL and FMX Styles and the Styledesigner...

I never used VCL-Styles before, because my last app for VCL is still on D2007 and we have written our own styling. 

Since XE 2, I use FMX only.

For FMX - of course - I had to use styling and the Bitmap-Style designer. I'm not so happy with this app. There is a QC Entry from 2018, RSP-22407, please support.

If you tried the Styledesigner there are many objects - that's fine - and PNG's for a different resolution. From my point of view, one big image is only helpful if you are using some kind of template for a well know graphic program. By comparing different styles you find out, that nearly every style has its own layout. Horrible. Unfortunately, there is no guide in which part of the graphic is used for which object/action. Also the Style/New creates different layouts. 

Ok, let's take it easy: Use a predefined style, save the png file, convert the colors, reload the png file, done... Isn't it? No... You have to adjust the font-colors because these colors are set individually. Wouldn't it be nice if the colors are taken from the png?
There is a "choose color under mouse" tool, but you can not open the png file and at the same time choose a color. The trick is to open on object, select background and open the rectangle editor. These windows could stay open while choosing the color.

How to uses these colors at runtime? There is no Color table in the style and if you change one color, the values are set to all objects. If you want to match a TRectangle to the given style the have to choose a control and get the color from there. So if your color settings are different from the SysColors, it's difficult. I like to have more than the given SysColors like clHelpTextColor, clWarnColor, clInfoColor. 

So how to select a color in the ObjectInspector? You can select "Red" or "clRed" but not "clMenu" or "clScrollBar". 

The Styles that are downloadable or included are - from my point of view - all too monochrome. Most dark styles are too dark (lol... perhaps, because I do not like dark-styles at all) and all of the colored- styles have only one dominant color. I like my UI uniform, but not so uniform. Colors help you to guide the user's attention. If you place some controls on a Panel / Rectangle with a different color you can show the user that these inputs are important or less important. Perhaps UserColor1, UserColor2..UserColorN would be nice.

How to get a button with an icon? You can use a button with an Icon or you can create a new entry in the object list, add an image to the "Big-Picture", select all rectangles for enabled, disabled, hot, focused. Copying a button is a piece of cake, but how to add the image? There is no build-in function. You have to take a graphic-editor to expand your png's (1x,1.5x,2x,3x) keep in mind to place your 5 images on the same spot, if not, you have to select all rectangle individually. But how? Solution: Write a tool to add Images. After your tool has created all png's you can import these images and select the rectangles. But where are the right corners? There is no grid  and if your icon has no outside Rectangle. you never find the right points (up/left,bottom/right). Wouldn't it be great if your tool could provide a config to do this selection on import of the png? And why is there no function to do this inside the Style designer? And why is there a big image depending on how to create and find all the right places? 

Wouldn't it be cool if you can provide single images for all functions/objects and on style-save, these images got composed (with no, or less spaces) into one big png? (for each resolution)! No Rectangle selection no guessing game where to find what? Perhaps single images are not so easy to create if you are a style-artist, but in this case, the Bitmap-Styledesigner should be able to export a uniform png with rectangles where to place your images. This image could be re-imported and could be striped into single images for later composing.

If you want to change the Font-Color for e.g. TabTextActiveNormal, you can open is (Font Dialog, no selection of pre-select colors) or you can change the color, but the actual color is not set in the color-dialog. So to change the color to a darker color you have to guess or you have to put in the colors for RGB. (Not with the clipboard.)

Many stuff to do... Like in RSP-22407 - I really have no time to write my own Styledesigner starting by New-FMX-Project.

Please leave a comment of your idea or if I'm totally wrong. ;-)



Wednesday, September 11, 2019

FDK - Unit-List is online!

I finally found some time put some kind of Information about my FDK on my website.

Full documentation is coming, but for a start you can have a look at the Unitlist.