Showing posts with label tip-of-the-day. Show all posts
Showing posts with label tip-of-the-day. Show all posts

Sunday, May 11, 2025

Delphi Tip of the Day: A Better Way to Center Modal Forms


Yesterday, I was going through some final aesthetic checks on my FMX desktop software application. I have two modal forms that popup up during click events. One is help about which I set to screen center. And the other contains code that centers the form on it's parent window.

I was testing the behavior of this form toggling between light and dark themes. I noticed that with light theme the window just appears but with the dark theme I could see the window move it's way from the top of the screen to it's centered position and then switch to dark.

In the OnShow event handler I was calculating Left and Top like I have always done to center the window. This was the first time I'd ever seen the window reposition itself. This is the first time I'd ever used a dark theme. And, this is the first major application I'd written with FMX.

Left := ParentForm.Left + (ParentForm.Width - Self.Width) div 2;
Top := ParentForm.Top + (ParentForm.Height - Self.Height) div 2;
To say the least, I was annoyed by this split second flash centering itself on the parent window. I tried all kinds of stuff to minimize this flash. Nothing work.

There's got to be a better way!

I didn't realize I had left the Position property of the form set to Default. In essence that is screen position (0,0), or the top-left corner. 

The first line of my code was moving the form horizontally from the left edge to the center of its parent. (I never saw that move happening). The second line of code was moving the form vertically from the top edge to the center of its parent (I saw this move happening).

I thought there's got to be a better way? I don't want customers seeing this screen moving like this. I tried setting the form's Visible property to False before the centering code and setting the Visible to True after. Nope, that is unauthorized. 

I tried in the OnCreate instead. Nope. I had created public properties for the forms Left and Top along with getters and setters. I created a whole elaborate scheme to support positioning this form where I wanted it.

Then it dawned on me. "Isn't there a screen position property?"

Yes, there is.
MainFormCenter! It's a thing!

FMX Form Position Property

Are you kidding me. MainFormCenter! It's a thing! When did this show up?

I immediately set the form Position property to MainFormCenter and added an Exit statement to the top of the OnShow event handler. 

And voila! 

It works like a champ. No more flashy form realignment stuff happening.

I then removed all the getters, setters, and properties I added for manually doing the form centering activity. Simple, cleaner code. 😎

BTW, the same thing exists for VCL.

VCL Form Position Property

DocWiki Links:

Enjoy
Semper Fi
Gunny Mike

https://zilchworks.com

Sunday, February 16, 2025

Delphi Tip of the Day: FMX FastReport Text Object (TfrxMemoView)

I've been playing around with FastReport in FMX. To be honest, I've been struggling a bit. So, today I decided to go back to square one and work through the FMX documentation on the FastReport website. https://www.fast-report.com/public_download/docs/FRVCL/online/en/index.html

"The "Text" object... No Problem.
HTML-tags in the "Text" object... Doesn't work as advertised.

The "Text" object (TfrxViewMemo) is extremely powerful. It accepts simple HTML tags that lets you modify a single text field in some really cool ways. It's kind of like a mini "Rich Text" object. 

Here is a what a working example is supposed to look like:



That is one text field with multiple effects applied to separate sections:
  • Bold
  • Italic
  • Bold and Italic
  • Superscript
  • Subscript
  • Color
I ran into an issue when I followed the example to create the "Orange" text. It didn't work. The Original example from the FastReports did not turn the text orange.


Using <font color="#FF8030"> did not display the text in orange. The text between the opening and closing font tags did not display at all. Seeing that the "red" font tag worked, I tried using the color name "orange". And it worked.


I then tried using the Alpha Color of  #FFFF8030 and it also worked.


I'm glad I was able to make the FastReport example work. The text object is very powerful. I experimented with several different Delphi Color name constants and they also worked. I did run into an issue with some of the obsolete color name constants, such as MoneyGreen. The FastReport designer did not recognize "MoneyGreen" as a valid integer. It did however take the MoneyGreen HEX equivalent of #FFC0DCC0.

I decided to create a the following cheat sheet of all the font color names that FastReport text object will recognize.

Name Color HEX Code

Aliceblue

Aliceblue

#FFF0F8FF

Antiquewhite

Antiquewhite

#FFFAEBD7

Aqua

Aqua

#FF00FFFF

Aquamarine

Aquamarine

#FF7FFFD4

Azure

Azure

#FFF0FFFF

Beige

Beige

#FFF5F5DC

Bisque

Bisque

#FFFFE4C4

Black

Black

#FF000000

Blanchedalmond

Blanchedalmond

#FFFFEBCD

Blue

Blue

#FF0000FF

Blueviolet

Blueviolet

#FF8A2BE2

Brown

Brown

#FFA52A2A

Burlywood

Burlywood

#FFDEB887

Cadetblue

Cadetblue

#FF5F9EA0

Chartreuse

Chartreuse

#FF7FFF00

Chocolate

Chocolate

#FFD2691E

Coral

Coral

#FFFF7F50

Cornflowerblue

Cornflowerblue

#FF6495ED

Cornsilk

Cornsilk

#FFFFF8DC

Crimson

Crimson

#FFDC143C

Cyan

Cyan

#FF00FFFF

Darkblue

Darkblue

#FF00008B

Darkcyan

Darkcyan

#FF008B8B

Darkgoldenrod

Darkgoldenrod

#FFB8860B

Darkgray

Darkgray

#FFA9A9A9

Darkgreen

Darkgreen

#FF006400

Darkgrey

Darkgrey

#FFA9A9A9

Darkkhaki

Darkkhaki

#FFBDB76B

Darkmagenta

Darkmagenta

#FF8B008B

Darkolivegreen

Darkolivegreen

#FF556B2F

Darkorange

Darkorange

#FFFF8C00

Darkorchid

Darkorchid

#FF9932CC

Darkred

Darkred

#FF8B0000

Darksalmon

Darksalmon

#FFE9967A

Darkseagreen

Darkseagreen

#FF8FBC8F

Darkslateblue

Darkslateblue

#FF483D8B

Darkslategray

Darkslategray

#FF2F4F4F

Darkslategrey

Darkslategrey

#FF2F4F4F

Darkturquoise

Darkturquoise

#FF00CED1

Darkviolet

Darkviolet

#FF9400D3

Deeppink

Deeppink

#FFFF1493

Deepskyblue

Deepskyblue

#FF00BFFF

Dimgray

Dimgray

#FF696969

Dimgrey

Dimgrey

#FF696969

Dodgerblue

Dodgerblue

#FF1E90FF

Firebrick

Firebrick

#FFB22222

Floralwhite

Floralwhite

#FFFFFAF0

Forestgreen

Forestgreen

#FF228B22

Fuchsia

Fuchsia

#FFFF00FF

Gainsboro

Gainsboro

#FFDCDCDC

Ghostwhite

Ghostwhite

#FFF8F8FF

Gold

Gold

#FFFFD700

Goldenrod

Goldenrod

#FFDAA520

Gray

Gray

#FF808080

Green

Green

#FF008000

Greenyellow

Greenyellow

#FFADFF2F

Grey

Grey

#FF808080

Honeydew

Honeydew

#FFF0FFF0

Hotpink

Hotpink

#FFFF69B4

Indianred

Indianred

#FFCD5C5C

Indigo

Indigo

#FF4B0082

Ivory

Ivory

#FFFFFFF0

Khaki

Khaki

#FFF0E68C

Lavender

Lavender

#FFE6E6FA

Lavenderblush

Lavenderblush

#FFFFF0F5

Lawngreen

Lawngreen

#FF7CFC00

Lemonchiffon

Lemonchiffon

#FFFFFACD

Lightblue

Lightblue

#FFADD8E6

Lightcoral

Lightcoral

#FFF08080

Lightcyan

Lightcyan

#FFE0FFFF

Lightgoldenrodyellow

Lightgoldenrodyellow

#FFFAFAD2

Lightgray

Lightgray

#FFD3D3D3

Lightgreen

Lightgreen

#FF90EE90

Lightgrey

Lightgrey

#FFD3D3D3

Lightpink

Lightpink

#FFFFB6C1

Lightsalmon

Lightsalmon

#FFFFA07A

Lightseagreen

Lightseagreen

#FF20B2AA

Lightskyblue

Lightskyblue

#FF87CEFA

Lightslategray

Lightslategray

#FF778899

Lightslategrey

Lightslategrey

#FF778899

Lightsteelblue

Lightsteelblue

#FFB0C4DE

Lightyellow

Lightyellow

#FFFFFFE0

Lime

Lime

#FF00FF00

Limegreen

Limegreen

#FF32CD32

Linen

Linen

#FFFAF0E6

Magenta

Magenta

#FFFF00FF

Maroon

Maroon

#FF800000

Mediumaquamarine

Mediumaquamarine

#FF66CDAA

Mediumblue

Mediumblue

#FF0000CD

Mediumorchid

Mediumorchid

#FFBA55D3

Mediumpurple

Mediumpurple

#FF9370DB

Mediumseagreen

Mediumseagreen

#FF3CB371

Mediumslateblue

Mediumslateblue

#FF7B68EE

Mediumspringgreen

Mediumspringgreen

#FF00FA9A

Mediumturquoise

Mediumturquoise

#FF48D1CC

Mediumvioletred

Mediumvioletred

#FFC71585

Midnightblue

Midnightblue

#FF191970

Mintcream

Mintcream

#FFF5FFFA

Mistyrose

Mistyrose

#FFFFE4E1

Moccasin

Moccasin

#FFFFE4B5

Navajowhite

Navajowhite

#FFFFDEAD

Navy

Navy

#FF000080

Oldlace

Oldlace

#FFFDF5E6

Olive

Olive

#FF808000

Olivedrab

Olivedrab

#FF6B8E23

Orange

Orange

#FFFFA500

Orangered

Orangered

#FFFF4500

Orchid

Orchid

#FFDA70D6

Palegoldenrod

Palegoldenrod

#FFEEE8AA

Palegreen

Palegreen

#FF98FB98

Paleturquoise

Paleturquoise

#FFAFEEEE

Palevioletred

Palevioletred

#FFDB7093

Papayawhip

Papayawhip

#FFFFEFD5

Peachpuff

Peachpuff

#FFFFDAB9

Peru

Peru

#FFCD853F

Pink

Pink

#FFFFC0CB

Plum

Plum

#FFDDA0DD

Powderblue

Powderblue

#FFB0E0E6

Purple

Purple

#FF800080

Red

Red

#FFFF0000

Rosybrown

Rosybrown

#FFBC8F8F

Royalblue

Royalblue

#FF4169E1

Saddlebrown

Saddlebrown

#FF8B4513

Salmon

Salmon

#FFFA8072

Sandybrown

Sandybrown

#FFF4A460

Seagreen

Seagreen

#FF2E8B57

Seashell

Seashell

#FFFFF5EE

Sienna

Sienna

#FFA0522D

Silver

Silver

#FFC0C0C0

Skyblue

Skyblue

#FF87CEEB

Slateblue

Slateblue

#FF6A5ACD

Slategray

Slategray

#FF708090

Slategrey

Slategrey

#FF708090

Snow

Snow

#FFFFFAFA

Springgreen

Springgreen

#FF00FF7F

Steelblue

Steelblue

#FF4682B4

Tan

Tan

#FFD2B48C

Teal

Teal

#FF008080

Thistle

Thistle

#FFD8BFD8

Tomato

Tomato

#FFFF6347

Turquoise

Turquoise

#FF40E0D0

Violet

Violet

#FFEE82EE

Wheat

Wheat

#FFF5DEB3

White

White

#FFFFFFFF

Whitesmoke

Whitesmoke

#FFF5F5F5

Yellow

Yellow

#FFFFFF00

Yellowgreen

Yellowgreen

#FF9ACD32

Osolete Color Names Use HEX Code

LtGray

LtGray

#FFC0C0C0

MedGray

MedGray

#FFA0A0A0

DkGray

DkGray

#FF808080

MoneyGreen

MoneyGreen

#FFC0DCC0

LegacySkyBlue

LegacySkyBlue

#FFF0CAA6

Cream

Cream

#FFF0FBFF



Enjoy!
Semper Fi
Gunny Mike

Thursday, January 2, 2025

Tip of the Day - Everyday is an Etch-A-Sketch

Sometimes all you need is a little motivation.

Everyday is an Etch-A-Sketch.



Sometimes, every hour is an Etch-A-Sketch.

And sometimes, every minute is an Etch-A-Sketch.


Happy New Year,
Gunny Mike

Saturday, September 14, 2024

Delphi Tip of the Day: The Delphi Magazine Total Collection

I'm always looking for ways to improve my Delphi skills. Sometimes, this takes me down a rabbit hole. And each time, these little side trips never answer "Yes" to the question "Will this help me ship?"  

Last week I went down the "global variables are bad" rabbit hole. 🐇🕳

Global Variables Are Bad

I opened my copy of "The Delphi Magazine Total Collection" looking for some inspiration. And, I found a 6 Part series called "Effective Delphi Class Engineering" written by David Baer. I'm slowly working my way through these articles.

Issue: 57 Effective Delphi Class Engineering 1:
Crossing The Chasm


David Baer kicks off a new series of articles aimed at all of us who are reluctant, confused or ill-informed on what object-oriented development is all about. The goal is to demonstrate, clearly and without jargon-loaded obfuscation, how to design, create and use Delphi classes to make your development more productive.
Issue: 59 Effective Delphi Class Engineering 2:
Welcome To The Machine


David Baer continues his series on practical object orientation by putting Delphi’s object machinery under a magnifying glass. He examines topics such as memory management, method calling, protocols and other compiler- related issues.
Issue: 60 Effective Delphi Class Engineering 3:
Skyrocketing Property


David Baer thinks properties are wonderful and this month gives us insights and advice on how they can best be put to use in our classes.
Issue: 62 Effective Delphi Class Engineering Part 4:
The TObject Of My


David Baer focuses on inheritance in this part of his popular series on object oriented development in Delphi.
Issue: 63 Effective Delphi Class Engineering Part 5:
You Are TEgg Man... I AM TWalrus


David Baer has not gone mad (though he may have been listening to too many old Beatles albums!): this instalment of his series continues his practical real-world discussion of polymorphism and inheritance.
Issue: 65 Effective Delphi Class Engineering Part 6:
To Talk Of Many Things


David Baer concludes his series on developing Delphi classes with a miscellany of sound advice, ranging from events to exceptions, RTTI and message handling.



Part 1 of Baer's series of articles, refenced short paper written by Marco Cantu called "When RAD is bad", which I found it on the internet archive. 

https://web.archive.org/web/20001120081900/http://community.borland.com/devnews/article/1,1714,10463,00.html  

But that's not all I found. I found a download link to the entire "The Delphi Magazine Total Collection Issues 1 - 139 (April 1995 to March 2007)"

https://archive.org/details/the-delphi-magazine-total-collection


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

Sunday, September 1, 2024

Delphi Tip of the Day: How to Keep Your Code Folded in Delphi 12

I like the "Code Folding" feature of  Delphi. However, I noticed that every time I reopened a project in Delphi 12 where I had previously folded the code, the code was no longer folded.

To keep your code folded in Delphi 12 you need to turn on the Save project desktop when closing option inside the IDE.

Tools > Options > IDE > Saving and Recovering

This option is unchecked in the default, out-of-the-box setup.


Delphi 12 also includes a new feature called Save editor state when closing a tab any time
https://docwiki.embarcadero.com/RADStudio/Athens/en/Saving_and_Recovering

Save editor state when closing a tab any time When selected, the current state for the views is saved before closing it. State info includes collapsed regions, cursor/caret position, and bookmarks.

This allows you to close and reopen a tab within the same editing session, and when the tab is reopened it will display exactly as it was when it was closed. This is similar to the Save project desktop when closing setting but functions all the time, not just when closing and reopening a whole project.

This option can only be enabled when Save project desktop when closing is checked.

Let me know in the comments what other out-of-the-box tweaks you like to make to a brand new Delphi install.

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


Saturday, July 13, 2024

Delphi Tip of the Day: Always Use the MenuBar for FMX Desktop Applications

A couple months ago, I watch the video replay "The fundamental secrets of good UI design" done by Ian Barker. Around the 33:15 mark, Barker talks about supporting "dark mode", have a listen:

Transcript:

"One of the things you really should do at a very bare minimum if you do nothing else please support dark mode. And this is kind of a personal beg from me. As I said before I do get these floaters in my eyes, I can see perfectly well you know, I'm not blind or anything like that. I'm shortsighted which is why I have glasses but if you support dark mode you will make my life a lot easier. And other people that have visual  issues as well some people get migraines and things like that dark mode helps."

https://www.youtube.com/live/TL2YVio_eTo?si=GUzsPoZriiIdyfbj&t=1995

I never considered supporting dark mode

Until I watched this video, I never considered supporting dark mode in the current rewrite of my Zilch software. So I began looking into how to incorporate FMX styles. It was confusing at first. Then I got the hang of it. I decided to go with the "Air.Style" that comes with Delphi.

David Cornenelius' book "Fearless Cross-Platform Development with Delphi" and Andrea Magni's book "Delphi GUI Programming with Delphi" were big helps understanding FMX styles.

There were a couple of tweaks I had to make. The Air.Style is a vector style which means it does not use the bitmap designer. It is similar to how Cascading Style Sheets are used in web development. The graphic elements are drawn using SVG paths. 

FMX Main Menu component can't be styled 

The biggest surprise was the TMainMenu component. It turns out the FMX Main Menu component can't be styled. The Embarcadero FMX Style Viewer was showing a Main Menu that was styled how come my Main Menu wasn't styled?

fmx-style-viewer-air
FMX Style Viewer - Air.Style

I didn't want my application to have some stuff styled and some stuff not styled. Then I discovered FMX includes a MenuBar component which does take styling. And that is what is used by the FMX Style Viewer. So, I slowly and methodically swapped out the MainMenu component for the MenuBar component.

Always use the MenuBar for FMX desktop applications


FMX MainMenu vs MenuBar

My recommendation is to skip using the MainMenu component when developing FMX desktop applications and ALWAYS use the MenuBar component.

You will be happy. Your customers will be happy.

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




Friday, January 5, 2024

Delphi Tip of the Day: Prevent SQLite Date Headaches by using a GetDateAs_YYYYMMDD Function

Working with Date data can be very tricky. I recently encountered an "Invalid argument to date encode", error while trying to update a SQLite database table.


This placed a value of 0000-00-00 into the date field of my SQLite table.

Here is the original code which caused the error.

function TForm1.GetOneOffDateAsDate: TDate;
begin
  Result := DateEdit1.Date;
end;

procedure TForm1.SQLInsertPayment;
begin
  qryO.SQL.Clear;

  qryO.SQL.Add( ' INSERT INTO OneOffPayments    ');
  qryO.SQL.Add( '             (                 ');
  qryO.SQL.Add( '             OneOffDate,       ');
  qryO.SQL.Add( '             OneOffPayment     ');
  qryO.SQL.Add( '             )                 ');
  qryO.SQL.Add( '      VALUES (                 ');
  qryO.SQL.Add( '             :ood,             ');
  qryO.SQL.Add( '             :oop              ');
  qryO.SQL.Add( '             );                ');

  qryO.ParamByName( 'ood' ).Value := GetOneOffDateAsDate;
  qryO.ParamByName( 'oop' ).Value := GetOneOffAmount;

  qryO.ExecSQL;
end;

The getter function GetOneOffDateAsDate passes in a TDate which doesn't play nicely with FireDAC. Fortunately, the fix is quite simple. I found a fantastic explanation for this error on stackoverflow which states FireDAC expects DATE data type values to be a string in the fixed format of YYYY-MM-DD.

FireDAC Expects DATE data types
to be strings formatted as YYYY-MM-DD

So I created another getter function to format the date data as a YYYY-MM-DD string.
Problem solved!

Updated code passing FireDAC a YYYY-MM-DD string

function TForm1.GetOneOffDateAs_YYYYMMDD: String;
begin
  Result := FormatDateTime('YYYY-MM-DD', DateEdit1.Date);
end;

procedure TForm1.SQLInsertPayment;
begin
  qryO.SQL.Clear;

  qryO.SQL.Add( ' INSERT INTO OneOffPayments    ');
  qryO.SQL.Add( '             (                 ');
  qryO.SQL.Add( '             OneOffDate,       ');
  qryO.SQL.Add( '             OneOffPayment     ');
  qryO.SQL.Add( '             )                 ');
  qryO.SQL.Add( '      VALUES (                 ');
  qryO.SQL.Add( '             :ood,             ');
  qryO.SQL.Add( '             :oop              ');
  qryO.SQL.Add( '             );                ');

  qryO.ParamByName( 'ood' ).Value := GetOneOffDateAs_YYYYMMDD;
  qryO.ParamByName( 'oop' ).Value := GetOneOffAmount;

  qryO.ExecSQL;
end;

Happy coding!


Enjoy!
Gunny Mike
https://zilchworks.com

Wednesday, December 20, 2023

Delphi Tip of the Day: Use Your Own Unique Prefix for Types and Constants

I'm in the process of converting an old Delphi 5 VCL application to Delphi 11 FMX. Yeah, I have Delphi 12 but I'm waiting for the first bug release before I start using it. Well, this morning I learned a valuable lesson. A lesson which stopped me dead in my tracks. 

There's nothing stopping you from creating an already existing type!

I was making some refactoring changes to my code. I didn't realize I was about to make a huge mistake. I went plodding ahead pleased with the progress I was making and admiring the beautiful, refactored code I was creating. When boom... I renamed a type that stepped on a type already inside the System.UITypes unit.

There's nothing to stop you from creating an already existing type. Of course I didn't use the preview changes function. I just hit go!

I had defined my own enumerated type called TMyImageIndex. I decided to just simply call it TImageIndex. So, that's what I did using Refactor > Rename type TMyImageIndex CTRL+SHIFT+E

I knew I messed up when I saw way too much code show up in the results panel.

How dare Embarcadero define a type called TImageIndex

WTF.  If it already existed the IDE should have prevented me or at least warned me. How dare Embarcadero define a type called TImageIndex.

type
//TImageIndex = (iiAdd = 2, iiUpdate = 3);)
  TZwImageIndex = (iiAdd = 2, iiUpdate = 3);)

const
  ZW_WIDTH_COLUMN_GLYPH  = 20;
  ZW_WIDTH_COLUMN_DATE   = 90;
  ZW_WIDTH_COLUMN_AMOUNT = 74

It took me about 30 minutes, but I was able to get the original code back in place, And working.

So going forward I have created my own unique prefix of  TZw (Zw = ZilchWorks). Going forward I will preface all Types and Constants.

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

Saturday, October 28, 2023

How to get the RSS Feed of YouTube Channels

Disclaimer: This post contains affiliate links, which means I may earn a small commission if you click through and make a purchase, at no extra cost to you. Your support helps keep this blog running – thank you!

I am a big fan of Harry Stahl's book "Cross-Platform Development with Delphi 10.2 & FireMonkey for Windows, MAC OS X (macOS) & Linux". I purchased this book in May 2021 and it has helped me several times as I'm porting my Zilch application from Delphi 5 VCL to Delphi 11 FMX.

Here's are Amazon links to Stahl's book:


I like to maintain RSS feeds of my favorite Delphi blogs. So, I went looking to see if Stahl has a blog I could add to my Outlook RSS Feeds. I found a couple of Stahl's websites. He does have a few blog posts but they are not easily converted into an RSS feed. 

Does YouTube support RSS feeds?

However, Stahl has a fairly active YouTube channel called Programming with Delphi. https://www.youtube.com/@programmingwithdelphi 

I wondered if YouTube supports RSS feeds? The answer is, YES!

Open Chrome and go to the YouTube channel you want to snag the RSS feed from. Right-click and choose the View page source option.



Then click the Line wrap checkbox in the top left corner of Chrome.



Press Ctrl-F to open the search box and enter rssurl.
Click and drag your mouse to highlight the URL associated with the rssurl attribute.
Press Ctrl-C to copy this highlighted URL to the clip board.
Your copied URL should look similar to the value below.

https://www.youtube.com/feeds/videos.xml?channel_id=UCiUVNZgsZZhziFL4oy-evEA


There you have it. That's all there is to grabbing the RSS Feed URL for any YouTube channel.

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

Note: Some links in this post are affiliate links, meaning I may receive a small commission if you make a purchase. This helps support my work – thank you for your understanding.


Sunday, May 7, 2023

Pseudo Code File Logic: Open > New > Save > Save As

Just finished working out the logic for handling file logic:

File Open
File New
File Save
File Save As

This assumes you are keeping track of the following:

  • Current Filename
  • Changes to file data
I've been wrestling with this one for a few days. And then it finally hit me. "Hey, Exit can be your friend."

Exit can be your friend







Within the last year, my thinking has been influenced by Jeff Patton and his book "User Story Mapping". At work I have been involved in many meetings/discussions where everyone is in agreement that we need to implement "Solution X". However, everyone has their own interpretation of what "Solution X" is.

https://www.amazon.com/User-Story-Mapping-Discover-Product/dp/1491904909


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


Monday, July 11, 2022

Delphi Tip of the Day - Environment Variables used only by the Delphi IDE

 I wanted a quick, down-and-dirty, reference to only those variables used by the Delphi IDE. Inside the IDE you can navigate to Tools > Options > IDE > Environment Variables. This will list all the Environment Variables currently in use. Those belonging to Delph and those outside of Delphi. However, that is not what I was looking for. I just wanted the Environment Variables specific to the Delphi IDE.

Generating this list was a three step process which involved some code I found here. 
http://delphiexamples.com/systeminfo/envtrings.html

Step 1. I entered and ran the code from the above link. I then copied and pasted the contents of the memo to a separate text file called EnVars-Delphi-IDE.txt.

Step 2. I closed Delphi and ran the program again from the saved location. I then copied and pasted the contents of the memo to a file called EnVars-Without-Delphi-IDE.txt.

Step 3. I then navigated to the Delphi BDSBIN location and ran the Beyond Compare utility BCompareLite.exe. I did a text compare of  EnVars-Delphi-IDE.txt and EnVars-Without-Delphi-IDE.txt looking only for the differences.


I simply copied all the text from the left-had side and saved it as EnVars-Delphi-IDE-Only.txt. And now I have my quick down and dirty list of Delphi IDE Environment Variables.

Here the list generated from my computer. YMMV

BDS=C:\program files (x86)\embarcadero\studio\22.0
BDSAppDataBaseDir=BDS
BDSBIN=C:\program files (x86)\embarcadero\studio\22.0\bin
BDSCatalogRepository=C:\Users\Mike\Documents\Embarcadero\Studio\22.0\CatalogRepository
BDSCatalogRepositoryAllUsers=C:\Users\Public\Documents\Embarcadero\Studio\22.0\CatalogRepository
BDSCOMMONDIR=C:\Users\Public\Documents\Embarcadero\Studio\22.0
BDSINCLUDE=C:\program files (x86)\embarcadero\studio\22.0\include
BDSLIB=C:\program files (x86)\embarcadero\studio\22.0\lib
BDSPLATFORMSDKSDIR=C:\Users\Mike\Documents\Embarcadero\Studio\SDKs
BDSPROFILESDIR=C:\Users\Mike\Documents\Embarcadero\Studio\Profiles
BDSPROJECTSDIR=C:\Users\Mike\Documents\Embarcadero\Studio\Projects
BDSUSERDIR=C:\Users\Mike\Documents\Embarcadero\Studio\22.0
DELPHI=C:\program files (x86)\embarcadero\studio\22.0
DEMOSDIR=C:\Users\Public\Documents\Embarcadero\Studio\22.0\Samples
FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer
FPS_BROWSER_USER_PROFILE_STRING=Default
IBREDISTDIR=C:\Users\Public\Documents\Embarcadero\InterBase\redist\InterBase2020
IB_PROTOCOL=developer_ib2020
InterBase=C:\program files (x86)\embarcadero\studio\22.0\InterBase2020
Path=C:\Users\Public\Documents\Embarcadero\InterBase\redist\InterBase2020\IDE_spoof
ProductVersion=22.0
SESSIONNAME=Console

Beyond Compare is a fantastic tool written with Delphi. The lite version is included with your purchase of Delphi. For more information about Beyond Compare visit their website: 

https://www.scootersoftware.com/

Enjoy,
Gunny Mike
https://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


Saturday, April 24, 2021

Delphi Tip of the Day - Toggle Visibility On/Off

I'm porting over one of my Delphi 5 VCL, desktop applications to FMX. The target audience are Windows and macOS users. I'm not focused on mobile at this juncture. I'm spending quite a bit of time on the User Experience (UX). I guess you would call this approach "Desktop UX First".

I want to give the user the option of showing or hiding panels. I've decided to place this functionality in two places:

  1. On the main menu as an option.
  2. On the bottom tool bar as a button.
The first thing that came to mind was testing the "IsChecked" state of the main menu option. I slept on it and came back to the drawing board the next day. Instead of thinking about trapping clicks, I thought about what the intent of the click really was. And the answer is to show or hide the panel.

If the user clicks either the main menu option or the toolbar button I want the panel to show or hide. Both of these options need to work together behind the scenes. The intent of either click focuses on the "visibility" of the panel. And wouldn't you know, TPanel has a Visible property.

Visible is a boolean value, meaning it has only two states. True/False. And in Delphi there is a very cleaver way to toggle the state of a boolean value. This can be a little tricky to wrap your had around at first. However, once you understand it, you'll love it.

Boolean Value becomes not Boolean Value;
Boolean Value (True) becomes not Boolean Value (True);
Boolean Value (False) becomes not Boolean Value (False);
Boolean Value := not Boolean Value;

Panel.Visibile becomes not Panel.Visibile;
Panel.Visibile (True) becomes not Panel.Visibile (True);
Panel.Visibile (False) becomes not Panel.Visibile (False);
Panel.Visibile := not Panel.Visibile;

The statement Panel.Visibile := not Panel.Visibile; 
toggles the value, back and forth between True and False.

Let's see how to put this to use in the real world. In Delphi create a new FMX application. 
Click File > New > Multi-Device Application - Delphi and choose Blank Application.

Add the following components:
TMainMenu
TPanel x2
TToolbar
TButton
TSplitter
TStatusBar

Structure the components so they are parented like this:



Your form should look similar to this:


The goal is to toggle the Left Panel visibility. When you first run the application the form opens with the default settings. We want both the MenuItem (Show Left Panel) and the ToolBar Button to work together.




Hiding the Left Panel the form changes accordingly.


Regardless of which method was used to Show/Hide the left panel both items stay in synch by calling on procedure ToggleLeftPanelOnOff.

I'm testing the Sender to make sure it was invoked by either a TMenuItem or a TButton control before I toggle the panel visibility. Although it's not displayed here this allows for calling ToggleLeftPanelOnOff from inside the form's OnShow method in essence setting the correct values without toggling the panels visibility.

Here is the program code:

unit Unit1;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.StdCtrls,
  FMX.Controls.Presentation, FMX.Menus;

type
  TForm1 = class(TForm)
    MainMenu1: TMainMenu;
    StatusBar1: TStatusBar;
    pnlLeft: TPanel;
    pnlMain: TPanel;
    splLeft: TSplitter;
    tbarMain: TToolBar;
    btnTBarLeft: TButton;
    mnuFile: TMenuItem;
    menuOptions: TMenuItem;
    mnuShowLeftPanel: TMenuItem;
    mnuClose: TMenuItem;
    procedure mnuCloseClick(Sender: TObject);
    procedure mnuShowLeftPanelClick(Sender: TObject);
    procedure btnTBarLeftClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
   procedure ToggleLeftPanelOnOff(Sender: TObject);
  end;

var
  Form1: TForm1;

implementation

{$R *.fmx}

procedure TForm1.btnTBarLeftClick(Sender: TObject);
begin
  ToggleLeftPanelOnOff(Sender);
end;

procedure TForm1.mnuCloseClick(Sender: TObject);
begin
  Close;
end;

procedure TForm1.mnuShowLeftPanelClick(Sender: TObject);
begin
  ToggleLeftPanelOnOff(Sender);
end;

procedure TForm1.ToggleLeftPanelOnOff(Sender: TObject);
begin
  // ==================================================================
  // Only toggle visibility if invoked by a menuitem or button click.
  // ==================================================================
  if (Sender is TMenuItem) or (Sender is TButton) then
    pnlLeft.Visible := not pnlLeft.visible;

  // ==================================================================
  // Set menuitem and button properties
  // ==================================================================
  if pnlLeft.Visible then
  begin
    mnuShowLeftPanel.IsChecked := True;
    btnTBarLeft.StyleLookup := 'arrowlefttoolbutton';
  end
  else
  begin
    mnuShowLeftPanel.IsChecked := False;
    btnTBarLeft.StyleLookup := 'arrowrighttoolbutton';
  end;

end;

end.

Here is the text version of the Form:


object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Toggle Demo'
  ClientHeight = 480
  ClientWidth = 640
  FormFactor.Width = 320
  FormFactor.Height = 480
  FormFactor.Devices = [Desktop]
  DesignerMasterStyle = 0
  object StatusBar1: TStatusBar
    Position.Y = 458.000000000000000000
    ShowSizeGrip = True
    Size.Width = 640.000000000000000000
    Size.Height = 22.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 1
  end
  object pnlLeft: TPanel
    Align = Left
    Size.Width = 161.000000000000000000
    Size.Height = 458.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 2
  end
  object pnlMain: TPanel
    Align = Client
    Size.Width = 475.000000000000000000
    Size.Height = 458.000000000000000000
    Size.PlatformDefault = False
    TabOrder = 3
    object tbarMain: TToolBar
      Align = Bottom
      Position.Y = 418.000000000000000000
      Size.Width = 475.000000000000000000
      Size.Height = 40.000000000000000000
      Size.PlatformDefault = False
      TabOrder = 0
      object btnTBarLeft: TButton
        Align = Left
        Size.Width = 40.000000000000000000
        Size.Height = 40.000000000000000000
        Size.PlatformDefault = False
        StyleLookup = 'arrowlefttoolbutton'
        TabOrder = 0
        Text = 'btnTBarLeft'
        OnClick = btnTBarLeftClick
      end
    end
  end
  object splLeft: TSplitter
    Align = Left
    Cursor = crHSplit
    MinSize = 20.000000000000000000
    Position.X = 161.000000000000000000
    Size.Width = 4.000000000000000000
    Size.Height = 458.000000000000000000
    Size.PlatformDefault = False
  end
  object MainMenu1: TMainMenu
    Left = 304
    Top = 224
    object mnuFile: TMenuItem
      Text = 'File'
      object mnuClose: TMenuItem
        Locked = True
        Text = 'Close'
        OnClick = mnuCloseClick
      end
    end
    object menuOptions: TMenuItem
      Text = 'Options'
      object mnuShowLeftPanel: TMenuItem
        Locked = True
        IsChecked = True
        Text = 'Show Left Panel'
        OnClick = mnuShowLeftPanelClick
      end
    end
  end
end


Enjoy,
Gunny Mike