Sunday, January 16, 2022

Book Review: Delphi GUI Programming with FireMonkey (Part 1)

I purchased the book Delphi GUI Programming with FireMonkey by Andrea Magni on November 7, 2020. I dove in head first with great enthusiasm only to get derailed early on. It happened when I tried to follow the topic Understanding the Style Designer in chapter 2.


As someone who knows almost nothing about FireMonkey these four and one-half pages soured my learning and turned me against this book and it's author. I tried reaching out to the author directly and received a curt response basically telling me that the examples in his book were not meant to be step-by-step. From that moment on I let this book sit on the shelf and collect dust.

That was a foolish mistake on my part. 

The Style Designer is a central part of FireMonkey and FMX. It is my opinion, that the author introduced this complex topic much too early in the book. It was presented with just a small smattering of knowledge and guidance. Leading me to three days of frustration because I could not make the Style Designer match what I saw in the book. The style designer is much too complex a topic to simply be glossed over in this fashion. A more fitting title for this topic would be First Glance at the Style Designer.

Don't Judge a Book by Only 4 Pages

If you are new to FMX and FireMonkey, and you want to get the most out of this book, I highly recommend you skip the topic Understanding the Style Designer in Chapter 2 (print: 34-38, pdf: 31-35). No understanding will happen. Instead, I recommend you watch this 50 minute YouTube video by Ray Konopka called Customizing Controls with FMX Styles.


After you have a better understanding of the FMX Style Designer, you may want to come back to the topic Understanding the Style Designer in this book.

You can best sum up my attitude about this book (and it's author) by the phrase "Don't judge a book by only 4 pages". I owe Magni an apology for holding a grudge against him because of 4 stinkin pages (and one email) in a book. 

"Andrea, I'm sorry."

I finally picked up Magni's book (again) last week. Actually I did a search for "Live Bindings" of my digital Delphi books which lead me to pick up Magni's book of the shelf. I opened up to Chapter 4, Discovering Lists and Advanced Components to a huge surprise. The printed copy of my book went from page 104 to page 157. Pages 105 through 156 are missing.

I contacted Packt Publishing to let them know of the misprint. All is good, a new printed copy is on the way.

At this point I was committed and had to fall back on reading the PDF version of Magni's book. I recently had cataract surgery on both eyes so I was very hesitant. Reading PDF books and manuals always leads to eyestrain at best or headaches at worst. That's when I discovered you can customize the background and font colors of a PDF document. See my post "Tip of the Day - How to change the text color of a PDF document" for instructions on how to do this.

I'm only part way through Chapter 4: Discovering Lists and Advanced Components and so far, Magni had done a fairly descent job. I have downloaded the source code for this book. I find it very helpful to have Delphi up and running along side reading the customized PDF. I open the example projects and play along with the reading to get a better understanding. 

Magni has done a a great job organizing the source code for this book. There is a separate chapter containing projects for each chapter. Each project within a given chapter has it's own folder. It is very well organized. The folders seem to be named intuitively. However, I find it very helpful to rename each folder and preface each folder name with the page number. That way I can quickly associate which project goes with with page or section of the book. As a plus, any un-numbered folders means I haven't opened that project and most likely haven't read that section of the book in detail.


I'm not sure when or if I will get finished with Magni's book. I'm just glad I overcame my stubbornness and opened his book back up again. I do know I have a need to and look forward to learning the following:

  • Chapter 4 Discovering Lists and Advanced Components
    •  ListBox
    •  ListViews
    •  Treeviews
    •  Grids
  • Chapter 5 Using FireDAC in FMX Applications
  • Chapter 6 Implementing Data Binding
  • Chapter 7 Understanding FMX Style Concept
  • Chapter 8 Divide and Conquer with TFrameStand (Maybe)

Bottom Line: Buy this book. Skip pages 34-38 (print), 31-35 (pdf).

Semper Fi,
Gunny Mike
zilchworks.com

Saturday, January 15, 2022

Tip of the Day - How to change the text color of a PDF document.

I was reading Andrea Magni's book Delphi GUI Programming with FireMonkey and realized I am missing pages 105-156. Packt Publishing is having a new print copied sent to me. Anyway, the PDF copy of the book is 100% complete.
I've always dreaded having to read PDF books for two reasons:
  • I don't like the way the pages jump from one page to another
  • The standard black text on a white background hurts my eyes and makes them tired.
I recently discovered two things you can change about PDF books (documents) that have made a huge difference for me. 

One is smooth scrolling. I thought that all pdf's jumped from the bottom of the page to the top of the next page. Not true. This is a setting. 

The second thing I discovered is the ability to change the color of the text within a pdf document. The standard black text on white background rally hurts my eyes. By changing the background and text color it is much more enjoyable to read.

This video shows you how to set smooth scrolling and change the text and background colors within a PDF document.


Enjoy,
Gunny Mike


Wednesday, December 15, 2021

FMX Desktop - Restrict Form Size on Windows and macOS

I'm in the process of porting over an old VCL application to FMX. At this time I'm only concerned with creating a desktop application that will run on Windows and macOS. One of the VCL features I like is the ability to set the forms minimum width and height properties. This prevents the user from making the application ridiculously small and unusable.

With a VCL application this is accomplished by simply entering the desired values in the MinHeight and MinWidth properties of the forms Constraints. The example below sets the VCL forms minimum height to 540 and the minimum width to 720.

Unfortunately, these properties do not exist within FMX Muilti-Device applications. In order to impose size constraints in FMX you have to write some code in the OnResize event handler. 

The simplest way to accomplish this would be to right some code similar to this:

const
  MinW = 720;
  MinH = 540;
begin
  if Width  < MinW then Width  := MinW;
  If Height < MinH then Height := MinH;
end;

This works. However it produces a horrible flickering effect when you continue to drag the mouse inside the boundaries specified within the OnResize event handler.

Windows Form Constraints with Flickering


What about the macOS? Does it flicker? The answer is no. The macOS respects the size constraints with no flickering issue:

macOS Form Constraints no Flickering


So the issue only happen on Windows PC's. 

I may be oversensitive here but I do not like this flickering at all. In my mind it gives the sense of an unprofessional appearance. Some end users may not care one bit about this and that's fine. However, it really bugs me. I want to prevent this from happening.

So I went looking for a solution and found one on stackoverflow. The code simulates a mouseUp event if the cursor moves inside the boundaries.

Windows Form Constraints with No Flickering

This is accomplished by making a Windows API Mouse Event call inside the OnResize event handler. It's not perfect but it does prevent the flickering from happening.

Add this to the Uses clause
Winapi.Windows

Modify the onResize event handler to simulate the mouseUp event.

const
  MinW = 720;
  MinH = 540;
begin
  if Width < MinW then 
  begin
    Width := MinW;
    mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  end;
  If Height < MinH then 
  begin
    Height := MinH;
    mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
  end;
end;

This code works great! It stops Windows PC's from flickering. However, we are not done yet. We have to wrap special tags around the Windows Only code so it is ignored by the macOS.

Modify the Uses clause as follows:

uses
{$IFDEF MSWINDOWS}
  Winapi.Windows,
{$ENDIF}
  System.SysUtils, System.Types, System.UITypes, System.Classes, 
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, 
  FMX.Dialogs, FMX.Controls.Presentation, FMX.StdCtrls;

Modify the onResize event handler as follows

procedure TForm1.FormResize(Sender: TObject);
const
  MinW = 720;
  MinH = 540;
begin
  if Width < MinW then 
  begin
    Width := MinW;
    {$IFDEF MSWINDOWS}
      //prevent form flickering on resize below constraints
      mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    {$ENDIF}  
  end;
  If Height < MinH then 
  begin
    Height := MinH;
    {$IFDEF MSWINDOWS}
      //prevent form flickering on resize below constraints
      mouse_event(MOUSEEVENTF_ABSOLUTE or MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    {$ENDIF}  
  end;
end;

Stay tuned for more FMX Desktop discoveries. 

Related Articles:
What Every Delphi Developer Should Know About Writing for Windows and Mac

Enjoy
Semper Fi
Gunny Mike
https://zilchworks.com

end.

Friday, December 3, 2021

The Biggest Mistake I Made in 2021

 I know this year isn't over yet but I'm pretty sure I won't make a bigger mistake between now and January 1st. 

Mike has been selling a software product written in Turbo Pascal & Delphi for 30 years. Mike's software was mentioned on the television show Good Morning America. Mike got very excited. Mike updated his website making the 30-second Good Morning America television segment center stage. Nobody cares Mike's software got mentioned on television (except Mike). Mike turned off potential customers who visited his website. Mike's sales dropped. Mike's a jerk. Don't be like Mike.

This was one of the hardest lessons I learned. 

I was so sure my would-be customers would feel just as excited about my software getting praise on national television as me. So sure in fact, that I posted a video of my software getting mentioned front and center on my website. And not just on the home page... but on every page.

Wrong! 

People don't care about me. People care about themselves.

People don't care about you.
People care about themselves.

It was Saturday morning, August 21, 2021. I was sitting on the couch in my living room watching cartoons with my granddaughter. And my phone dinged. I received an notification of a sale. A few minutes later another ding, another sale. I checked the real-time website stats and to my surprise there were 53 visitors on my site all at the same time.

I started googling trying to figure out what was causing this frenzy of visitors to my website. And by luck I found a video segment that had just aired on the Good Morning America television show. 

The total segment was about 4 minutes long. The last 35-40 seconds is where my software ZilchWorks was mentioned. So I trimmed the video down to the last 40 seconds because that's the part that talked about my software. Proof again that people only care about themselves. Why else would I have trimmed down this video.

I then retooled my entire website and made this "Look what I can do" video front and center. I foolishly thought this would drawn in website visitors.

Lessons Learned:

  • People don't care about you. They care about themselves.
  • Customers want to know what you can do for them.
  • Enjoy the media success. Treat it as validation.
  • This too shall pass applies to both good and bad.

Enjoy!
Semper Fi,
Gunny Mike

Friday, July 30, 2021

Delphi: Inheriting Parent Properties

The ability to inherit Parent properties is very convenient. Let's say you have a form with several controls on that form. If you wanted to change the default font from "Tahoma" to "Segoe UI" wouldn't it be nice to only have to make that change in one spot and voila, the change happens everywhere?

Well that is what inheriting the Parent properties is all about.

Unfortunately, not all the Parent properties get inherited. The font color is one of those properties that gets inherited by some controls but not all controls. I created this short video to show what happens to some of the most used VCL controls when you change the forms Font Color and Font Family.



https://youtu.be/M3VWsqPodJM

So, be careful and don't assume that one single change to the forms properties will get propagated throughout your entire application.

Enjoy!
Semper Fi,
Gunny Mike
https:\\zilchworks.com

Saturday, July 17, 2021

CodeRage 3 Replays - Oldies but Goodies

This morning I was looking for a video on how to debug an application with the Delphi IDE. I came across a two-minute video on YouTube by Francois Gaillard. It was a teaser video intended to pique your interest for the segment he did at Code Rage 3. Unfortunately, there was not a link to the full blown presentation.

I found a link to the Code Rage 3 replays on the way back machine. You can find the original webpage using this link. https://web.archive.org/web/20090815150549/http://conferences.embarcadero.com/coderage/article/38874

There are a lot of really interesting replays from Code Rage 3. Unfortunately, the recordings are done using Adobe Flash which has been discontinued. However all is not lost. You can download a stand-alone Flash Player from the Adobe website using this link 

https://www.adobe.com/support/flashplayer/debug_downloads.html


Delphi Debugging for Dummies by Francois Gaillard


After you download and unzip the replays you will see two ".swf" files. one called Session.swf and one called Session_controller.swf. Make sure to open the Session_controller.swf using the Flash Player program downloaded from the Adobe site. This will give you the the status bar with play and pause buttons along with the thumbtack progress bar.

Below is the list of Code Rage 3 presentation with download links.

Delphi / RAD Studio

C++ Builder

Delphi Prism

JBuilder

Delphi for PHP

InterBase

3rdRail/TurboRuby

Database Tools

General Topics

Sessions Presented in Spanish

Sessions Presented in Portuguese

Enjoy
Semper Fi
Gunny Mike
https://zilchworks.com

The link to the stand-alone Adobe Flash Player came from an article called "How to Play Adobe Flash SWF Files Outside Your Web Browser" on howtogeek.com. https://www.howtogeek.com/438141/how-to-play-adobe-flash-swf-files-outside-your-web-browser/

Saturday, June 5, 2021

Mobile Storage Access (Note to Self)

 I am nowhere near creating apps for the mobile community. That doesn't mean I won't be in the future. So, I'm writing this as a "Note to Self" so when the time comes I'll have a nice handy reference.

If you are currently developing mobile apps you may find this discussion on Delphi-PRAXiS helpful and interesting.

How do users easily bring their desktop data to mobile devices?

You may also want to view the following YouTube video called Storage access with Android 11



Enjoy,
Semper Fi
Gunny Mike
https://zilchworks.com