Sunday, August 11, 2019

Delphi Tip of the Day - Rounding (Again!)

It's been over 7 years since I dove into the mystical world of rounding numbers within Delphi. It's amazing how much code actually gets written in support of the main stuff an application does. I am so glad I wrote my blog... it's the one place I can go back to when I find gaps from my hard drive crash of 2018.

I ran into the old familiar rounding issue - again. And of course, I didn't have the code I used to get it squared away.

My original blog post from 7 years ago, "Rounding the Currency type like they taught us in school", explains the issue in full detail and nothing has changed with regard to how Delphi handles rounding.

And as usual David Heffernan gave...


So I went back to the Stack Overflow post to revisit the answers given to my original question. And as usual David Heffernan gave a very straightforward and succinct answer.

{---------------------------------------------------------------}
{ Added 2019-08-07                                              }
{                                                               }
{ Used to solve the Delphi's rounding function.                 }
{                                                               }
{ https://stackoverflow.com/q/10965759/195983                   }
{ https://stackoverflow.com/a/10970283/195983                   }
{---------------------------------------------------------------}
Function RoundTo2dp (Value: Currency): Currency;
begin
  Result := Trunc(Value*100+IfThen(Value>0, 0.5, -0.5))/100;
end;

I added the code to my StrStuff unit. (Does everyone have a StrStuff unit or is it just me?) And it did not compile. So, when I got done cussing out Heffernan for putting bum code out there, I did some digging.

It turns out there are two IfThen functions. One in the SystemStrUtils unit and the other one in the System.Math unit. And of course, I chose the wrong unit.

This specific IfThen function is from System.Math


This specific IfThen function is from the System.Math unit:
unit Strstuff;

interface

uses System.Sysutils, System.Math;

Function RoundTo2dp (Value: Currency): Currency;
And of course after I put the correct unit in the uses clause it worked like a champ. I must admit, it felt good cussing out Heffernan. But as usual... he's right. Again!

Thank you David.


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


External Reference Update: 2021-06-04



Monday, July 29, 2019

Stop saying "I don't have time" - Say "It's not a priority"

That little switch from saying "I don't have time", to saying "It's not a priority" is a HUGE game changer. I learned about this from a co-worker last week. She didn't invent it... she heard it and passed it on to me. So, I'm passing it on to you.

I started using it immediately. It's my new mantra. I've mostly said it quietly only too myself so far. An I can attest, it's already made a big difference in my life. I thought about making the title of the post click-bait. For example:

Stop saying "I don't have time", say this instead...


Making people click into the site to get the punchline. But that's not what this is about. This is about leveraging the smallest of things, and turning it into the biggest of life changers. As my good friend Bob Wight, would say, "Riley, that's what you call a woomera". A small little device that when used, gains a tremendous advantage over not using it. (R.I.P. Bob, I miss you a lot).

One of my favorite songs is "We will never pass this way again" by Seals and Crofts. It speaks to me in so many ways. And it's true! So while we go through life, why not pick up a little nugget every now, from wherever we find it, and pass it on to the rest of the world. You never know the significance one small little thought will have on someone.

Enjoy the rest of your day and tackle those priorities!

Semper Fi,
Gunny Mike
zilchworks.com

Sunday, July 28, 2019

Delphi Tip of the Day - TODO or not TODO

I tend to be a scatter-brain when it comes to Delphi.

Really? Tend to be? "No Gunny. You are a scatter-brain when it comes to Delphi." I can hear all of you who know me saying this. That's fine.. I fully embrace it. I am a scatter-brain, especially when it comes to everything Delphi. There is so much I want to learn and do.

I have been trying to update my very old, flagship product Zilch Standard for 8 years. I've made zero progress. Why? Two reasons:
  1. I am a scatter-brain.
  2. I was of the mindset I needed to start from scratch and completely redesign everything.

When I was a teenager,
I would go to the ...


When I was a teenager, I would go to the library with a specific idea of what I wanted to read about. I'd head straight to those bookshelves and start eyeballing titles. "Nope." "Nope." "Uh Uh." 'Nah." 'Oh, that looks interesting." "Hey that reminds me of  X."  "Where is the 'X' section." Off I'd go to the "X" section,  and repeat this process until I found something all consuming.

This happens to me all the time with Delphi. My thirst for learning overtakes me and I lose focus on actually making progress inside the IDE. 

How about the other issue, having the mindset of completely redesigning everything from scratch? Well that was squelched when my hard drive crashed and I lost over three-and-a-half years of code. Gone! Poof! It actually turned out to be a blessing. It has forced me to look at things with a whole different perspective. 

That brings me to today's Delphi Tip of the Day.

As I was going through and porting over my old Delphi 5 code, I started doing that "scatter-brain" thing again. I first noticed it when I was updating the Main Menu functionality. "Hey, you know what would be cool, an MRU (Most Recently Used) file list." "Yeah lets add that". And off I went on a quest to learn how to build an MRU list.

Two hours later when I went to make another Nespresso (yeah I'm a coffee snob), it hit me. "Hey Gunny, an MRU list is not the objective. Put it on the back burner."

My back burner items tend to get lost and disappear.


My back burner items tend to get lost and disappear. Then I get frustrated because I can't remember all those "To Do" items I have on the back burner. "Hey wait a minute. Doesn't Delphi have a 'To Do' list function built in? 

Yes, Delphi does indeed have TODO functionality and I started using it the other day. However, in traditional Gunny Fashion it's not your normal TODO.
"If we are going to get wet up to our knees, we might as well get wet up to our waist and get the job done right."
I often use that phrase at my day job. Especially when there are two or three of us gathered around working on an immediate issue. It's different when it's an urgent need that must get done before you go home. 

So when I get ankle deep on a "new" feature I'd like to add, that is not a priority, I add it to my TODO list in Delphi. However, I also include the links to the website articles that will be useful when the time comes to implement them later. For example here is my current TODO list:


If you drill down into the highlighted "TODO" item it brings up the source code:

var
  HWnd: THandle;
  MR_Result : Word;

begin
  {---------------------------------------------------------------}
  { Use this code for retail version                              }
  {---------------------------------------------------------------}
  Hwnd := FindWindow('TMainForm','Zilch Standard - Main Screen');
  {---------------------------------------------------------------}
  { Use this code for trial version                               }
  {---------------------------------------------------------------}
  //Hwnd := FindWindow('TMainForm','Zilch Standard (Evaluation Copy) - Main Screen');

  {---------------------------------------------------------------}
  { TODO 3 -oMJR -cPhase 2 : Set Focus to running application     }
  {---------------------------------------------------------------}
  // Refer to these links when for implementing this TODO item
  // https://codeoncode.blogspot.com/2016/12/get-processid-by-programname-include.html
  // https://stackoverflow.com/questions/47598473/how-can-i-call-getwindowthreadprocessid-in-delphi-10-2
  {---------------------------------------------------------------}
   If Hwnd <> 0 then SetForeGroundWindow(GetForeGroundWindow())
  else
  begin
    Application.Title := 'Zilch';
    Application.CreateForm(TMainForm, MainForm);
    Application.CreateForm(TNoPrintDlg, NoPrintDlg);
    Application.CreateForm(TCreditorInfo, CreditorInfo);
    Application.CreateForm(TDisclaim_Save, Disclaim_Save);
    {---------------------------------------------------------------}
    { Use this code for US Marine Corps distribution                }
    {---------------------------------------------------------------}
    {
    MR_Result := USMC_End_User_License.ShowModal;
    If MR_Result = idYes then
    begin
      Application.ProcessMessages;
      Application.Run;
    end;
    }
    {---------------------------------------------------------------}
    { Use this code for genral public distribution                  }
    {---------------------------------------------------------------}
    Application.ProcessMessages;
    Application.Run;
  end;
end.

This way I can do a little "ankle deep" research and keep it preserved on the back burner for latter use without the risk of loosing it. It allows me to scratch the itch at the time it itches and lets me go knee deep later on when the time comes to dive in.

Going forward I will make extensive use of the TODO feature in Delphi. I hope this has helped you better understand TODO's and how they can help you scratch the itch when it itches.

It's time to publish this and get back to work!

Enjoy,
Gunny Mike
https://zilchworks.com

Saturday, July 27, 2019

Delphi Makes Updating Old Code Very Easy (Hidden Gem)

When my computer hard drive crashed in October 2018 I was really upset. The hard drive was completely shot and unrecoverable. I lost all of the code I had been working on... ARRRGH! The last backup I had was taken in March 2015. Yup, 3 1/2 years of Delphi, Evelated DB, and SQL code GONE!

Intellectually, I accepted this had happened and purchased Carbonite within a few days of getting my computer back this time with a solid state drive. However, I had not emotionally accepted I lost all that work. Well, last weekend I completely came to grips with the situation. Had a good cry. Decided to pickup what I could and start anew updating my old software.

The last time I compiled this project was 2008. So, I opened my Delphi 2005 project with Delphi 10.3 and clicked "Run" and held my breath.

It looked like crap. The default font is the old "System" font. The background colors didn't register properly. I couldn't see some of the stuff because the font color and background color was the same. This was broken. That didn't look right. Then the big "Ah Ha!" moment came...

Hey wait a minute... I just got a clean compile on code written with Delphi 2005 that is hasn't been touched since 2008 . That's amazing!


I'm slowly working my way through enhancing the look and feel. I'll be adding new functionality as well. It's amazing how a few minor changes takes thing to a whole new level.

Before: 2008 (Delphi 5)

After: 2019 (Delphi Rio)

So now I'm updating this code so I looks modern. In the process I will be replacing old functions with better, faster, more readable functions. Not all of them, just those using dumb code. I started swapping out function names in small little pieces. Repeating the Save, Run, Test, Close, Next Change. Save, Run, Test, Close, Next Change for every function I replaced.

Work Smarter Not Harder!


I wanted to see if I had replaced all the old occurrences of one function with the new function.

By pure dumb luck I right-clicked on a function name and found "Search For Usages...". Whoa. This is a great tool. And I'm going to show you how to use it.

Step 1: Click on a function in any unit.

Step 2: Right-Click on the function name and choose Search For Usages

Step 3: Click Search

Step 4: Expand the results



Step 5: Double-Clicking takes you to the source code

Step 6: Repeat the search making sure there are no more changes needed

Step 7: Clean up when done

I am so grateful I found this nice little utility. I just had to stop making code changes and share it with you guys.

Enjoy,
Gunny Mike
zilchworks.com

Sunday, June 9, 2019

Say what you mean and mean what you say!

How often are you or your words misinterpreted? Do you even know? Would someone tell you? Or would you go on with life thinking everything is just honky dory. Only to find out later things were not just fine, you only thought they were.



I attended a Toastmasters Leadership Institute training session and was introduced to a "word exercise". This was the first-time I ever heard this done, or given any thought to how a simple phrase could possibly be misinterpreted. It never dawned on me that someone might take to mean what I said differently than I meant it.

Read this sentence to yourself: "I never said I thought your idea was bad."

Fairy straightforward, right. How did this sound to you? Is this something you may have even said to someone? I know I've said this or something very similar to someone.

Let's see how many different ways this can be interpreted. Read each sentence below putting emphasis on the "bolded" word below.

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

"I never said I thought your idea was bad."

Interesting right? Yeah that was the same reaction I had. It never occurred to me that someone might see or hear what I say in a different context than they way I mean it.

That explains a lot. Today, we are constantly texting or emailing people. It's not always your fault if you or what you say gets taken the wrong way. It depends on the way it gets interpreted by the recipient.

So even if you say what you mean and mean what you say it might still be taken differently.

Enjoy!

Semper Fi,
Gunny Mike
https://capecodgunny.com

Your feedback, and comments are always welcome. Don't forget to subscribe for email notifications of new posts.

Saturday, March 9, 2019

Delphi Tip of the Day - Forward Declarations. Solving the Chicken or the Egg Problem.

Today's Delphi Tip of the Day is about resolving "which came first, the chicken or the egg". Because Delphi is a strongly typed language you can't refer to something until it's been defined. However, there are situations where you want to refer to something NOW, but unfortunately it hasn't been defined yet.

In other words "I want the egg of that chicken. I know that chicken hasn't laid that egg yet. However, since I know that chicken is going to lay that egg (trust me I know), let me have that egg now."

This is where forward declarations come into play.

I was brought here by something that came up while reading Pawel Glowacki's book Expert Delphi. I'm on page 233 from Chapter 7 - Sensing the world. Pawel discusses the TSensorManager class in the System.Sensors unit.

There is main TSensorManager class that acts as a gateway to all sensor information. It has a Current: TSensorManager class property that is used to reference all sensor information. At the top of the System.Sensors unit, you can find a TSensoryCategory enumerated type that provides the top level categorization of all possible sensors: 

At this point my head was about to explode so I decided to open the System.Sensors unit and have a look at the actual code Pawel was referring to. Then it hit me.

What the hell is this empty class doing here? How can you have an empty class?
TSensorManager = class;
I remember going down this empty class learning path a while ago. But do you think I can remember what it was, or means. No. Obviously, I had not associated a nice, simple "word picture" to the meaning of this empty class. Because if I had, I would have remembered.

So now I have the nice, easy to remember, "Oh that's Delphi's way of resolving the chicken or the egg thing" word picture.

Have a look at this type definition snippet from the System.Sensors unit:"
type

  //
  //other type declarations
  //
  
  TSensorManager = class; //←-- egg reference
  
  TCustomSensor = class abstract
    public type
      TProperty = (UniqueID, Manufacturer, Model, SerialNo, Name, Description);
    private
      FOnDataChanged: TNotifyEvent;
      FOnSensorRemoved: TNotifyEvent;
      FOnStateChanged: TNotifyEvent;
      FManager: TSensorManager; //←-- egg reference
      FStarted: Boolean;
    //
    // other class definitions
    //
  end;
  
  //
  //other type declarations
  //

  TSensorManager = class abstract  //←--- chicken reference
  public type
    TFilters = TDictionary‹string tsensorfilter=""›;
  private class var
    FCurrentManager: TSensorManager;
    class function InternalGetSensorManager: TSensorManager; static;
    class constructor Create;
    class destructor Destroy;
  protected type
    TSensorManagerType = class of TSensorManager;
    //
    // other class definitions
    //
  end;

    
  //
  //other type declarations
  //

 implementation
The problem arises because there's a private field declaration in the TCustomerSensor class that references the TSensorManager class that doesn't exist yet. It's the damn "chicken or the egg" thing.

To get around this Delphi allows what is called a forward declaration.

This is not by any means the complete class definition. The complete class definition must be declared somewhere inside the same type declarations where the forward declaration resides.

Here are a couple useful links:

http://docwiki.embarcadero.com/RADStudio/Rio/en/Classes_and_Objects_(Delphi)#Forward_Declarations_and_Mutually_Dependent_Classes

http://www.delphibasics.co.uk/RTL.asp?Name=Class

Special Characters:
The  "‹" and "›" in the source code sections were created using the Alt + Keypad method.
https://www.keynotesupport.com/websites/special-characters-symbols.shtml


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

Monday, March 4, 2019

Delphi Tip of the Day - What is the "A" prefix I see used on parameters?

Today's Delphi Tip of the Day is all about consistent naming conventions. Consistency in the Delphi and Object Pascal language makes it easier to read and comprehend the code.

I have often wondered why the "A" prefix is used on Delphi parameters. Instead of just accepting it as some esoteric thing as I have done for the past twenty years, I googled around and found an answer. Have a look at the following code snippet:
constructor TPerson.Create(AFirstName, ALastName: string);
begin
  FirstName := AFirstName;
  LastName  := ALastName;
end;
The "A" in "AFirstName" and "ALastName" denotes an Argument as in the above constructor code example.

Typical naming conventions that are used are:
A := Argument
F := Field
T := Type
E := Exception
I := Interface
L := Local Variable
G := Global Variable
The key is to be consistent in all your code. If we as a Delphi community are consistent then it makes it much easier to communicate with each other.

See also:
Object Pascal Style Guide By: Charles Calvert
[Archive]

#delphi #tipoftheday #capecodgunny

Enjoy,
Gunny Mike
https://zilchworks.com

Sunday, February 24, 2019

Expert Delphi - Code Errata

For the past month I have been making my way through Pawel Gloawcki's book Expert Delphi. I love this book. I am having fun and learning so much. I completed the "Game of Memory" application from Chapter 4, and it works pretty good.


I initially ran into an issue running The Game of Memory on my Galaxy S9+. In portrait mode, if I selected "6 Pairs" it rendered two columns of six. However, only the top portion of the bottom two tiles displayed. I changed the TILE_MARGIN constant from 2 to 4 and it fixed the render problem.

I moved onto Chapter 5 - Firemonkey in 3D. I discovered an error from page 162 that took me over an hour to track down. I finally figured it out. The program is supposed to display a red 3D Pyramid. However, I was only getting a blank screen. I discoverd one of the private properties was not getting set.

  TWireframe = class(TControl3d)
  private
    FDrawColor: TAlphaColor;
    FEdges: TEdges;
    FPoints3D: TPoints3D;
    FDisplayed: Boolean;
  public
    constructor Create(AOwner: TComponent) ; override;
    destructor Destroy; override;
    procedure Render; override;
    property DrawColor: TAlphaColor read FDrawColor write FDrawColor;
    property Points3D: TPoints3D read FPoints3D;
    property Edges: TEdges read FEdges;
    property Displayed: Boolean read FDisplayed write FDisplayed;
  end;

It is the code for the constructor where the error is:

The private boolean field FDisplayed was not getting set to true.

constructor TWireframe.Create(AOwner: TComponent);
begin
  inherited;
  FPoints3D := TPoints3D.Create;
  FEdges := TEdges.Create;
  FDrawColor := TAlphaColorRec.Red;
end;



As soon as I added this code to the constructor it worked like it was supposed to.

constructor TWireframe.Create(AOwner: TComponent);
begin
  inherited;
  FPoints3D := TPoints3D.Create;
  FEdges := TEdges.Create;
  FDrawColor := TAlphaColorRec.Red;
  FDisplayed := True; // This is missing on page 162 of the book
end;


It probably wouldn't have taken me so long to figure this out if I was a more seasoned Delphi programmer. Oh well, it is what it is. So, for any of you who are reading or plan to read "Expert Delphi" keep this little tidbit in mind when you get to Chapter 5.

I have submitted an errata to the folks at https://packtpub.com

Enjoy,
Gunny Mike
https://zilchworks.com


Saturday, December 8, 2018

Code Rage 2018 Replay: What's New With RAD Studio 10.3 Rio

I was unable to attend Code Rage 2018 this year. I'd like to thank Embarcadero for making the replays available. In this video, Sarina Dupont, David Millington, and Marco Cantu discuss what's new with RAD Studio 10.3 Rio. I like the new changes to the IDE.

Code Rage 2018: RAD Studio 10.3 Rio Product Address
https://www.embarcaderoacademy.com/courses/441209/lectures/7010714


Q&A Slide 

10.3 Rio is now available!
https://community.idera.com/developer-tools/b/blog/posts/delphi-c-builder-and-rad-studio-10-3-rio-are-now-available

IDE Main Window:
https://community.idera.com/developer-tools/b/blog/posts/new-in-10-3-ide-ui-improvements-in-the-main-window

IDE and Project Options:
https://community.idera.com/developer-tools/b/blog/posts/new-in-rad-studio-10-3-options-dialog-improvements

GetIt, Compile and other dialogs:
https://community.idera.com/developer-tools/b/blog/posts/new-in-rad-studio-10-3-improvements-to-the-getit-new-items-and-compile-dialogs

C++17:
https://community.idera.com/developer-tools/b/blog/posts/new-in-rad-studio-10-3-c-17-asynchronous-c-code-completion-and-more

Delphi inline variables & type inference:
https://community.idera.com/developer-tools/b/blog/posts/introducing-inline-variables-in-the-delphi-language

Delphi RTL Improvements:
https://community.idera.com/developer-tools/b/blog/posts/delphi-rtl-improvements-in-10-3-rio

High DPI perMonitorV2 & GetSystemMetrics:
https://community.idera.com/developer-tools/b/blog/posts/vcl-support-for-per-monitor-v2-and-getsystemmetrics-coming-in-10-3

High DPI Image List:
https://community.idera.com/developer-tools/b/blog/posts/new-in-rad-studio-10-3-high-dpi-image-list-for-windows

Enjoy,
Gunny Mike
http://www.zilchworks.com

Wednesday, November 28, 2018

The 20-Second Hug

program TwentySecondHug;

{$APPTYPE CONSOLE}

{$R *.res}

uses
  System.SysUtils;

begin
  try
    Writeln('The 20-Second Hug');
    Writeln('Copyright (C) 2018 by Michael J. Riley');
    Writeln('(May be freely distributed worldwide)');
    Writeln('#20SecondHug #20SecondHugs #PilotLight ');
    Writeln(#13#10);
    Writeln('+--------------+');
    Writeln(' Instructions ');
    Writeln('+--------------+');
    Writeln(' 1. Squeeze recipient.');
    Writeln(' 2. Don''t let go until this window closes.');
    Sleep (20000); //Stay awake don't miss this part;
      { TODO 1 :
      Translate instructions into other languages.
      Ask Delphi programmers for help by putting
      translations in blog comments. }
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.

Enjoy,
Gunny Mike
zilchworks.com

Sunday, August 12, 2018

Delphi Book Collection

One week after I wrote about Warren Buffet's 25-5 rule I created my own "Top 5" list. However, this time I put a little twist on it. Instead of creating a to-do list of things I wanted to accomplish in the next six months, I created a list of the top 5 things I have accomplished within my lifetime. It took me about five or six days but I finally came up with my list.

#4 on my list: "Creating a software product back in 1991 that still generates sales today."

If you check the list of Delphi releases you'll notice that Delphi didn't exist in 1991. Turbo Pascal was the tool I used to create that first version of my software. Here is a picture of Zilch v1.11. Unfortunately, I do not have a copy of my very first version 1.0.

Zilch Version 1.11 (Version 1.0 not available)

Learning Turbo Pascal was fun. I owe my passion and desire for computer programming to Jeff Duntemann. He wrote a book called "Complete Turbo Pascal". It was that book that taught me everything I needed to know about computer programming, and the Pascal language. In fact, the reports within my software are pulled using the double-linked list example in his book. Duntemann does a brilliant job of explaining this concept.

That book is by far my absolute favorite programming book. I used several snippets of code, and in some cases entire routines from the examples in his book. Like the linked list routines. I remember getting close to being done. My software was about a month away from being released as shareware. And it dawned on me, "Holy crap. I've used a bunch of code from this book and it's copyrighted. Can I do this?" So I called Jeff and the conversation went something similar to this...

Me: Mr. Duntemann.

Jeff: Yes.

Me: You don't know me. My name is Michael Riley. I'm a US Marine developing software in my spare time.

Jeff: That's good. I like Marines.

Me: Mr. Duntemann, I've...

Jeff: Please call me Jeff not Mr. Duntemann.

Me: Okay. I've been using your book "Complete Turbo Pascal" to learn how to write my software. And I've embedded several of the code snippets into my software. The're all over the place. I've even used the complete linked-list code routines. Am I allowed to do this? Can I use your code in my own software?

Jeff: Of course. That's why I wrote the damn book.

Me: Whew, that's a relief. You have no idea how worried I was. I really like how you explained double linked lists.

Jeff: I get quite a few calls from people telling me they have my book and asking to explain something. I remember the phone ringing at 1 in the morning one time and I was explaining linked lists to this guy. I remember using a kite metaphor. You see it's like a kite with a tail, and attached to that tail is another kite with a tail. And attached to that tail is another kite. Kites and tails with attached kites keep going on and on and on.

I love this guy. That was 1991 and Jeff and I have been friends ever since. One of these days I'm going to have to get Jeff to sign this book. I've completely destroyed the spine. I even had to use clear shipping tape to hold the spine together.

Complete Turbo Pascal Third Edition - Jeff Duntemann

My books have been scattered all over my basement office. When I want one I go searching from pile to pile. Moving stuff, looking around. It's frustrating and not very productive. Arrrgh!

It's been like this for a long time. It's not just books that are unorganized. It's me. It's everything. Besides, the older I get the harder it is to keep track of stuff. Stuff I need to do. When it needs to get done. Who I owe it to. Who owes me stuff. All that stuff.

So, I dusted off my old Franklin Planner that I haven't used since 2010. Inserted the new planner pages on Wednesday night and started using it the next day. Life is so much better now. I set a task for organizing my basement home office on Saturday. Then I decided to gather up all my Delphi books and put them on one single bookshelf. Wow, I have quite the collection.

Click to enlarge image

And guess what? All those books are tied to my #4 lifetime accomplishment: "Creating a software product back in 1991 that still generates sales today".

However, it not about what I did. It's about people. The people who helped me while I was in the midst of doing the thing I did. Like I said, I owe my #4 to Jeff Duntemann. Without him this never would have happened. Look what it's lead to. It's because of Jeff that I stayed enthused, and stayed passionate. Passionate enough to buy 32 Delphi books over the past 28 years. Not to mention the eBooks sitting on my computer. Thank you Jeff.

Don't worry I've told this to Jeff already. He's not hearing this for the first time reading it here. What kind of guy do you think I am.

I have a challenge for you! I want you to create your own "Top 5" list of lifetime achievements.

It doesn't matter if it takes you a week, or two weeks, or longer. Just do it. Then sit and think about your accomplishments. Think long enough about them until you discover who helped you get there. And then, reach out to them and let them know.

Enjoy,
Gunny Mike
zilchworks.com



Sunday, May 20, 2018

Don't Just Code in Delphi, Think in Delphi

I have always struggled with fully understanding the object oriented nature of Delphi. I still struggle with it today. For example, I have tried to read Nick Hodge's book "Coding in Delphi" three times and can't get past page 23. I'm currently on page 96 of Pawel Glowaki's book "Expert Delphi" and had to stop because he talks about using the TTextWriter class which is a class with virtual abstract methods. Virtual Abstract Methods, are you kidding me. What the hell are Virtual Abstract Methods.

(Expert Delphi page 96) "Notice that the TTextWriter class is a class with virtual abstract methods that just define the interface to the text writing functionality so we need to use one of the text writer descendants such as TStringWriter."

Okay, so I get a small glimpse into what Pawel's talking about. These VAM's are just interface definitions. They don't really exist. The real functions exist somewhere else. In this case the TStringWriter class. I'm just barely hanging on here, but I'm hanging on.

I blame my Delphi ignorance on my lack of going back to square one and learning Delphi's OOP think from the beginning. At the time I started using Delphi I just plowed ahead and made the code work. I wanted a Windows program and that is all I cared about. Looking back at it, I'd say I forced Delphi to work like my top-down procedural thinking. I never fully embraced the Delphi OOP think.

Hodges, Glowaki, Cantu, and all the other Delphi authors out there think in Delphi. And if I want to understand them and be proficient in Delphi I need to think in Delphi too.

So, how do you think in Delphi?

You find a resource that explains Delphi in a simple straight-forward manner. Perhaps a resource that teaches you how Delphi came into being. Does such a resource exist? Yes. And I just so happened to have a copy on my bookshelf.


Here are three paragraphs from page 7 and 8. If these paragraphs speak to you like they did me, then I highly recommend you read the entire Turbo Pascal 5.5 Object Oriented Programming Guide.

The challenge of object-oriented programming (OOP) is that it sometimes requires you to set aside habits and ways of thinking about programming that have been considered standard for many years. Once that is done, however, OOP is simple, straight- forward, and superior for solving many of the problems that plague traditional software programs. 

A note to you who have done object-oriented programming in other languages: Put aside your previous impressions of OOP and learn Turbo Pascal 5.5's object-oriented features on their own terms. OOP is not one single way; it is a continuum of ideas. In its object philosophy, Turbo Pascal 5.5 is more like C++ than Smalltalk. Smalltalk is an interpreter, while from the beginning, Turbo Pascal has been a pure native code compiler. Native code compilers do things differently (and far more quickly) than interpreters. Turbo Pascal was designed to be a production development tool, not a research tool. 

And a note to you who haven't any notion at all what OOP is about: That's just as well. Too much hype, too much confusion, and too many people talking about something they don't understand have greatly muddied the waters in the last year or so. Strive to forget what people have told you about OOP. The best way (in fact, the only way) to learn anything useful about OOP is to do what you're about to do: Sit down and try it yourself.

I'm convinced this little 124 page resource will give me the solid foundation of Delphi think that I've  been missing. I was so excited to find this little gem and what it offers, I had to stop reading and tell you guys about it.

A copy is available on archive.org

Enjoy!

Semper Fi
Gunny Mike
zilchworks.com


Saturday, April 28, 2018

What do you, me, Warren Buffet, and his pilot have in common?

Success. Each one of us; you, me, Buffett, his pilot all want success. Whether we acknowledge it or not, we each hunger for success. So, what separates the exceptionally successful people from the rest of us?

Check out this story about Warren Buffet and his long-time pilot then you decide.




Mike Flint was Buffett's personal airplane pilot for 10 years. Flint had flown for 4 different U.S. Presidents before, so he was pretty good at flying. Yet he still felt as though he hadn't achieved all of the career and life goals that he wanted to.

So one day Buffett jokingly says to Flint: "The fact that you're still working for me tells me I'm not doing my job. You should be out going after more of your goals and dreams."

So Flint asks Buffett for his help, and Buffett tells him to go through this 3-step exercise.

Here's how it works (you can play along at home, too)…

STEP 1
Buffett started by asking Flint to write down his top 25 goals - the things that came to mind when he thought of success in his career and life. So, Flint took some time and wrote them down.

STEP 2
Then, Buffett asked Flint to review his list and circle his top 5 goals - the things that were most important to him and that he wanted more than anything else in the world.

This was a lot harder for Flint, since everything on his list was important to him (after all, that's why he wrote them down). But Warren insisted that he could only pick five, so after some time and thought, he made five circles.

"Are you sure these are the absolute highest priority for you?" Warren asked. Steve confidently replied that they were.

STEP 3
At this point, Flint had two lists. The 5 items he had circled were List A and the 20 items he hadn't circled were List B.

Warren now asked Flint when he planned to get to work on these top 5 goals and what his approach would be.

Flint explained, "Warren, these are the most important things in my life right now. I'm going to get to work on them right away. I'll start tomorrow. Actually, no I'll start tonight."

Flint went on to explain his plan, who he would enlist to help him, when he expected to complete each item…

And that's when Buffett asked him about the second list, "And what about these other 20 things on your list that you didn't circle? What is your plan for completing those?"

Flint replied, "Well the top 5 are my primary focus, but the other 20 come in at a close second. They are still important so I'll work on those intermittently as I see fit as I'm getting through my top 5. They aren't as urgent, but I still plan to give them a dedicated effort."

To which Buffett replied:

"No. You've got it wrong, Mike. Everything you didn't circle just became your 'avoid at all cost list.' No matter what, these things get no attention from you until you've succeeded with your top 5."

Semper Fi
Gunny Mike
zilchworks.com

Monday, March 5, 2018

Embarcadero Discontinues the Sale of Upgrade Products

I received an email today informing me that as of April 1, 2018 Embarcadero will discontinue the sale of upgrade products for Rad Studio, Delphi and C++ Builder.

My first reaction was "OMG here we go again." Bailey didn't do a very good job at explaining what this means to me, a non-subscription owner of Delphi 10 Seattle. Fortunately, Malcolm Groves put out a fantastic video that explains what this means and what it will cost going forward.


I also found out from Bailey that Embarcadero is offering a 25% discount until March 31, 2018. So, for a non-subscription Delphi Enterprise user like me, that means $1,824 US. Ouch!

After listening to Malcolm describe what is really going on here, I don't feel as panic stricken as I did when I first read the email. $1,824 will get me up-to-date with Delphi 10.2.2 and give me a 12 month update subscription. Next year when my current subscription runs out it should cost approximately 23% of the new user price or $809 which works out to be $68 per month.

Delphi Enterprise Non-Subscription Upgrade Cost

Year Annual Cost Monthly Cost
2018 $1,824 $152
2019 $809 $68

$809 is 23% of $3,514 (Current New User License)

Semper Fi
Gunny Mike
zilchworks.com

Saturday, January 13, 2018

Playing With Fire(Monkey)

If you are like me and have been apprehensive about using FireMonkey let me offer you a renewed sense of hope. It's unfortunate that this hopefulness comes as the Delphi community morns the loss of Pawel Glowacki. However, Pawel will continue to influence at least this Delphi programmer, perhaps you, and undoubtedly many, many more.

I discovered the existence of Pawel's "Expert Delphi" book while reading one of the many R.I.P. blog posts. I sent myself a reminder to go purchase his book. And, this weekend I did purchase his book. I'm glad I did. I look forward to "Playing with Fire(Monkey)"!

In August I blogged "Why My Next Software Product Will Be Windows VCL Only". Well, this book is not about the VCL. Makes my VCL statement kind of ironic, don't you think. This book is about using Delphi FireMonkey to create cross-platform Mobile Apps from one code base. I did not know this about his book when I wrote that post. Taking on a new coding platform is a daunting task. I'm stepping up to the plate and taking on this task with the help of Pawel's book. I welcome you to join me in discovering how to "Play with Fire(Monkey)".

Expert Delphi - Preface


The world of a mobile app developer is getting more and more complicated. The technology is not standing still. Every day, new versions of mobile operating systems are released to the market. Mobile devices are getting new capabilities. User expectations are constantly growing, and it is becoming increasingly harder to meet them.

The only way to meet and exceed all challenges in the contemporary world of mobile development is to become a developer superhero! Super heroes have super tools. In this book, we are going to embark on the journey of mastering Delphi development. We will learn how to gain amazing productivity powers and rapidly build stunning cross-platform mobile apps from one codebase.

We will start with getting comfortable with using the Delphi IDE. Then, we will review the key constructs of the Object Pascal language and everyday programmer tasks, so you can easily understand and write solid and maintainable source code. Over the course of this book, the fun levels are only going to increase. We will start our adventure with mobile development with Delphi from building small projects that will make you feel like a real Delphi developer. Having mastered simple things, you will be ready for doing more serious stuff. We will go deep into understanding the concept of FireMonkey styles, which is the cornerstone of building stunning cross-platform user interfaces that will make the difference in the end user experience of your apps. The rest of the journey is all about gaining practical knowledge of using more complex Delphi frameworks. We will get down to the metal and harness the full power of mobile hardware and operating systems. We will be working with sensors, extending to the Internet of Things, building data-driven user interfaces, embedding mobile databases, integrating with REST web services, architecting scalable, multiuser backends, and more.

This book is packed with practical code examples and best practices for you to become an excellent mobile developer!

Expert- Delphi - Table of Contents


1: FASTEN YOUR SEAT BELTS

  • Delphi installation
  • Delphi compilers and toolchains
  • Hello World app
  • Deploying to mobile devices
  • Summary

2: MIND YOUR LANGUAGE

  • Do you speak Object Pascal?
  • Object Pascal Phrase Book
  • Summary

3: PACKING UP YOUR TOOLBOX

  • Parallel Programming Library
  • Working with files
  • JSON
  • XML
  • Summary

4: PLAYING WITH FIREMONKEY

  • Drawing in code
  • Get moving with timers
  • The power of parenting
  • Touch me
  • Game of Memory
  • Summary

5: FIREMONKEY IN 3D

  • Cross-platform 3D rendering
  • Using Context3D
  • Custom Wireframe component
  • Objects 3D
  • Moving Earth
  • Building an interactive 3D scene
  • Using 3D models
  • Starfield simulation
  • Mixing 3D and 2D
  • Summary

6: BUILDING USER INTERFACES WITH STYLE

  • Working with built-in styles
  • Using custom styles
  • Embedding styles as resources
  • Customizing styles
  • Using frames
  • Working with inherited views
  • Previewing forms on devices
  • Summary

7: WORKING WITH MOBILE OPERATING SYSTEM

  • James Bond's toy
  • What I'm running on?
  • The life of an app
  • Sensing the world
  • Taking photos
  • Using share sheets
  • Camera, light, action!
  • Working with address book
  • Notify me!
  • Navigating the web
  • Working with maps
  • Creating and consuming Android services
  • Delphi language bridges
  • Summary

8: EXTENDING TO THE INTERNET OF THINGS

  • Communication protocols
  • Understanding BLE
  • Connecting to things with ThingConnect
  • Getting close with beacons
  • Proximity solutions with BeaconFence
  • App tethering
  • Summary

9: EMBEDDING DATABASES

  • Architecting data-driven apps
  • Modeling data
  • Choosing a database
  • Accessing databases with FireDAC
  • Building data-driven user interface
  • Using visual live bindings
  • Fast user interface prototyping
  • Summary

10: INTEGRATING WITH WEB SERVICES

  • Understanding web services
  • Native HTTP client
  • Consuming XML SOAP web services
  • Integrating with REST services
  • Backend as a service client
  • Integrating with the cloud
  • Summary

11: BUILDING MOBILE BACKENDS

  • Delphi and multi-tier architectures
  • Getting low-level with WebBroker
  • Do it yourself with DataSnap
  • Easy REST API publishing with RAD Server
  • Summary

12: APP DEPLOYMENT

  • Deploying to App Stores
  • Enhancing your apps
  • Summary

13: THE ROAD AHEAD

  • What we have learned
  • Staying on top of everything
  • Your next Delphi mobile app
  • Summary

Expert Delphi - Prerequisites

You are expected to have a basic knowledge of Delphi and an interest in building crossplatform mobile apps for Android and iOS.

The Delphi IDE is a Windows program, so you will need a physical or virtual Windows installation. In order to develop for iOS, you will need a Mac computer. You will also need an Enterprise or Architect license for Delphi itself. In the beginning of the first chapter of this book, we cover the installation process of Delphi in a great detail.

Purchase Link:

https://www.packtpub.com/application-development/expert-delphi

Semper Fi,
Gunny Mike
zilchworks.com

Thursday, January 4, 2018

I've Been Telling the Wrong Product Stories

This post has nothing to do with Delphi other than it's the software development tool I use. In November of last year I finally purchased Microsoft Office 365. A couple days later I received a promotional email introducing me to Microsoft Virtual Academy (https://mva.microsoft.com/).

I visited the MVA site, signed up for a free account, and by pure dumb luck stumbled across an amazing set of videos designed to teach you how to create stories. The video series is called "Crash Course: Analytics Storytelling for Impact". (https://goo.gl/oFEc9F) This video series was put together to teach people how to present data analytics in a very impactful way. Although it's focus is on how to present data analytics, it has a very unique set of videos all about stories and storytelling.

The storyteller is Mario Juarez and he is phenomenal. The third video "Definition of a Story" (https://goo.gl/L5e1g8) hit me like a ton of bricks. It was as if everything all of the sudden fell into place. All the previous stuff I had read or heard about marketing such as; don't sell features sell benefits finally made sense.

In the past no matter how hard I had tried I always wound up telling what Jaurez refers to as "transactional stories". The description of the thing I did. The transaction or process. What I built, how it works, the sequencing of events. Sound familiar.

The stories I need to tell are what Juarez calls "transcendent stories". These are stories of how human life changed because of the interaction with your product. Transcendent stories go to the place of human experience and human values and human meaning.

Watch this video series. They will change they way you talk about your products.

The first story I'm working on is for my Credit Card Math product. I've created a fictitious customer persona called Kate. The story I'm creating is "How Credit Card Math Saved Kate's Marriage." The story model I'm using is defined by Kurt Vonnegut as "Man in hole". (https://youtu.be/oP3c1h8v2ZQ)

Here's a sneak peak at Kate:


My first video is taking me longer than I expected. Hopefully it will be completed soon. I'm very excited to see how this whole process goes.


Semper Fi,
Gunny Mike
zilchworks.com

Sunday, December 10, 2017

The Lazarus Effect

I haven't been focused on much software development lately, I've been working on some marketing material which I hope to have completed soon. Then I will get back to software development.

Last night I was prodded by my friend Jeff Duntemann's post on Facebook regarding the release of Lazarus 1.8 (with FPC 3.0.4). He mentioned this stuff to me a few years back and said I should check it out. I have always been a die-hard Delphi fan so I gave it a casual, glancing thought and moved on.

Well, now may be the time to give Lazarus a throrough going-over. I downloaded Jeff's book this morning and read through the first 30 pages and then skipped ahead to the "Installation" chapter. I'm always leery of installing freeware stuff, it's never as simple as point, click, and install.

I had no idea that FreePascal was the compiler and Lazarus was the IDE. had always thought these were two competing products.

Hopefully before the end of the year I will get Lazarus and FreePascal installed and give it a whirl. I'll let you know what I think.





Lazarus
https://www.lazarus-ide.org/
http://wiki.lazarus.freepascal.org/

FreePascal
https://www.freepascal.org/
http://wiki.freepascal.org/

FreePascal From Square One by Jeff Duntemann (free book)
http://www.copperwood.com/pub/FreePascalFromSquareOne.pdf


Semper Fi,
Gunny Mike
zilchworks.com


Sunday, August 6, 2017

Why My Next Software Product Will Be Windows VCL Only

I started this blog back in 2009 as I slowly emerged from a severe case of burn-out. From that first day I've been consistently saying I'm working on an update to one of my software products. And I'm still saying that today. I'm like the Rip Van Winkle of Delphi programming. I basically dropped off the face of the Delphi coding world, woke up from an 8 year technology nap, and have been in a learning fog ever since.

I have been procrastinating at every turn, about every tool, and every methodology. The bottom-line is... I can't make a decision. Check out this common theme among some of my posts going back quite some time.

How do you get past the Analysis to Paralysis when working on a new project?
https://softwareengineering.stackexchange.com/questions/155621/

What is The Best Database for Delphi Desktop Applications that Supports Stored Procedures?
https://stackoverflow.com/questions/1619887/

I Took A Little Walk-About - But I'm Back (Shit or get of the pot)
http://capecodgunny.blogspot.com/2011/08/i-took-little-walk-about-but-im-back.html

Last week I heard about Warren Buffett's 25-5 Rule.  I've never heard it put quite that way before. Anyway, it got me to change my attitude about decision making.

For example:

Should the new release of my Zilch software be Windows?
Windows and Mac?
Windows, Mac, iOS, Android?
What about the Web version?

ENOUGH!

I'm going Windows VCL Only! Period. I made the decision and it's final. Making decisions is so liberating.

  • I am the most proficient with Delphi VCL.
  • I have a distribution channel and payment gateway for Windows already in-place. 
  • I have 25 years worth of Windows customers I can market my software upgrade to.
  • I can use the current development tool chain I already have.

2017 is the 25th anniversary of my original product launch. I need to get busy working on the things that matter most and ignoring everything else if I hope to get it released this year.

I don't care if the Warren Buffett story is true or not. It's a good thing. I encourage all of you to have a look at it.

Cheers!

Semper Fi,
Gunny Mike





Saturday, August 5, 2017

Error: Cannot Restore Form State--No TRzRegIniFile Component Specified

It's been a while since I fired up Delphi, about three months. And you know, it's true what they say "If you don't use it you loose it". I love my Raize Components now called Konopka VCL Controls, they make a lot of things very easy. For example, automatically remembering the size and position of form windows. I've used this dozens of times. It's a no-brainer.

So today, I was playing around with the DBGrid, trying different things. I created a new project with a Form and a Data Module. Added a lookup field to the grid. Just having fun and experimenting with stuff. One of the things I wanted to do but haven't got around to yet, was save the column widths of the grid after they've been resized. I find it annoying always having to resize the columns every time a program runs. That will be for another day.

Anyway, I decided I wanted to start by saving the state of the Main form window, just like I've done in the past. Drop a RzRegIniFile component on the Data Module. Drop an RzFormState component on the Main form. Set the RzFormState.RegIniFile property to the DM.RzRegIniFile component. And Voila... Done! Right!

NOT!

I kept getting the following error: "Cannot Restore Form State--No TRzRegIniFile Component Specified".



I'm going back and forth like a madman, checking things on the Data Module and the Main form. I tried dropping and re-adding the components. Nope. I started googling the error... nothing. Then it hits me. It's got to be a timing thing.

Yup! I opened the source file for the project and sure as shit, the Data Module was being created after the Main form.
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TForm4, Form4);
  Application.CreateForm(TDataModule5, DataModule5);
  Application.Run;
end.
I moved the creation of the Data Model before the Main form and bingo... works like a champ!
begin
  Application.Initialize;
  Application.MainFormOnTaskbar := True;
  Application.CreateForm(TDataModule5, DataModule5);
  Application.CreateForm(TForm4, Form4);
  Application.Run;
end.
I'm amazed how quickly I lost sight of this little detail. I was only away from Delphi for maybe three months. Gee Whiz.

Enjoy!

Semper Fi,
Gunny Mike

Saturday, May 13, 2017

Program to an Interface and not an Implementation

I have been struggling with trying to understand what it means to "Program to an interface and not an implementation." Nick Hodges said if he could teach new developers one thing it would be "program to an abstraction, not an implementation". This is the same thing. (wayback machine link)

So I asked Hodges to explain this to me. Instead of trying to regurgitate some sort of answer that might come up short of what I was looking for, he sent me a link to a fascinating thread on StackOverflow (https://goo.gl/PNq7bY). This really is a great read. After reading it I was close to understanding but still not getting all of it.

I have recently started reading Head First Design Patterns by Eric Freeman & Elisabeth Robson. This book does an absolutely fantastic job of describing the GoF design Patterns that Uncle Bob so bluntly told me I need to understand. To be quite honest, I never would have bought this book solely based on the cover. (Not buying this book would have been a mistake.)



Amazon: https://goo.gl/MVybeZ

On page 11 of Head First Design Patterns they point out Design Principal #2: "Program to an interface and not an implementation." They do an excellent job of explaining what this means. My ability to understand what they mean... "Not so much". This is even after reading page 11 three times and reading the entire SO link Hodges sent me.

Why am I so dim?
How come everyone else gets it but me?

Ah ha, it hits me.

Each Delphi Unit has an Interface section and an Implementation section. In Delphi these sections are like Public Scratch Paper and Private Scratch Paper. (https://goo.gl/B7U5RR) All Delphi noobs are taught to stick stuff in the Interface section that you want to share with other units and stick stuff in the Implementation section that you don't want other units to have access to.

That is NOT what it means to "Program to an Interface and not an Implementation."

I had to unlearn what I had known about Interface and Implementation because of my 25+ years of Turbo Pascal/Delphi. And relearn that there are different meanings associated with Interface and Implementation. Sometimes it takes the light bulb a long time to go on

My end goal in all of this "new learning" is to understand Dependency Injection and how to put DI to use when I design/redesign software. I'm slowly getting there. Delphi's Interface and Implementation sections have different usage and meaning than the OOP Design Principle: Program to an interface not an implementation.

So, what does it mean to "Program to an interface and not an implementation"?

You have to figure this out on your own. I'm not trying to be a smart ass here. Once you get it, you'll get it. Asking someone for a quick 5 minute explanation won't do it. You'll have to dig and keep trying until it makes sense for you. In learning this concept some people use widgets. Some use sprockets. Some use ducks. I like chess.

Think about the simplest piece in a chess game. The Pawn.

What's the same about every pawn?
What's different about each pawn?
If you forget about color, how many different pawns are there? 8, 1, 3, 4 ?
What about the pawn to the far-left?
What about the pawn to the far-right?
What about the pawn that reaches the last row?
How many different moves does a pawn have?
Do all pawns have the same moves?

Trying to understand what it means to "Program to an interface and not an implementation" requires a different way of thinking.

Here is my completely oversimplified chess example:
+--------------------------------+
| PawnMovement (Interface)       |
+--------------------------------+

+--------------------------------+
| PawnMovementImplementations    |
+--------------------------------+
ForwardOne 
ForwardTwo
AttackLeft
AttackRight
EnPassant

So to me learning how to "Program to an interface and not an implementation" means making sure your pawn has movement not what the pawn's movement is.

Think this:
Pawn1.PawnMovement.ForwardOne
Pawn1.PawnMovement.ForwardTwo
Pawn1.PawnMovement.AttackRight
Pawn1.PawnMovement.EnPassant

Don't Think this:
Pawn1.ForwardOne
Pawn1.ForwardTwo
Pawn1.AttackRight
Pawn1.EnPassant

Enjoy!

Semper Fi,
Gunny Mike