Wednesday, October 14, 2015

A Software Engineer's Hippocratic Oath

I ran across this interesting article by Phillip A. Laplante on the responsibilities of software developers. More than a decade after it was written, many of Laplante's ideas and observations still ring true.

Here's his proposed version of the Hippocratic oath for software engineers. Even if it never becomes a part of the sacred and occult investment rites1 which every developer must undergo, it contains a lot of truth.
I solemnly pledge, first, to do no harm to the software entrusted to me; to not knowingly adopt any harmful practice, nor to adopt any practice or tool that I do not fully understand. With fervor, I promise to abstain from whatever is deleterious and mischievous. I will do all in my power to expand my skills and understanding, and will maintain and elevate the standard of my profession. With loyalty will I endeavor to aid the stakeholders, to hold in confidence all information that comes to my knowledge in the practice of my calling, and to devote myself to the welfare of the project committed to my care.
I especially like the idea of developer as a steward of things that have been entrusted to her for a time. After all, isn't that what most of our lives are about anyway?

1 Which I just now realized I probably shouldn't have even mentioned in so public a forum as this here Internet Web Log is. Whoops! Sorry, Programmer Illuminati.

Thursday, October 1, 2015

Error Creating Form: Ancestor for 'TFormName' Not Found

So, this one has been bugging me for a while. I'm using Embarcadero's RAD Studio 10 Seattle, working on a sizable C++ application. For a few specific units, whenever I load them, I get the following message:
Error creating form: Ancestor for 'TFormName' not found.
(Of course, it actually said the name of my form, not 'TFormName'.)

And when this happens, my .dfm (Delphi Form) won't load, so I can't do anything with the design of that particular form. To work around this, I had to open the ancestor (or in at least one case, multiple ancestors), and leave them open in the IDE, before being able to view my form's .dfm at all.

So I double-checked all my include and lib paths, as well as my include statements in the headers of my .h files. I googled my fingers to the bone, looking for any answer I could find. Nothing.

Finally, I noticed that the form I was trying to inherit from wasn't even in the inheritable items list, which led me to this old post, and I knew I'd found the culprit.

In the end, the solution was spectacularly simple: Remove all problematic units from the project. Then, add them back in the appropriate order. No more error!

It really was as simple as this:

Friday, August 15, 2014

Solved: Unable to open file 'FIREDAC.STAN.FACTORY.OBJ'

Today, I kept getting this error in Embarcadero C++ Builder XE6 when trying to compile a pretty large project:
[ilink32 Error] Fatal: Unable to open file 'FIREDAC.STAN.FACTORY.OBJ'
My project referred to a library that had FireDAC components, though I wasn't using any of them. My project uses DBX, not FireDAC, and VCL instead of FMX.

FireDAC.lib was in the project includes in my .cbproj file, so I had no idea what was wrong.

I finally found a fix: drop a FireDAC component (I used FDConnection) on a form. Save all, compile, and it worked. Then, I just deleted the FDConnection from the form and I was good to go.

Wednesday, July 16, 2014

Changing Fire Monkey (FMX) TextSettings at Run Time

One of my beefs with Embarcadero's C++ Builder is that it is so hard to find decent documentation or tutorials on how to do even the simplest things with their visual tools. This is especially true if you're developing in C++ instead of Delphi.

I experienced a pretty steep learning curve with Embarcadero's Visual Class Library (VCL) -- not because it is especially complicated, but because I couldn't find much good documentation for it.

Right now, I am building an FMX application, which is similar in a lot of ways to VCL. However, one thing has changed a lot: the styles are now driven by stylesheets.

For example, in VCL, it was relatively easy to change the font attributes of dynamically created elements at run time. Not so with FMX.

After several hours of fruitless googling, I still haven't figured out how to change my StyleLookup for a dynamically created TEdit. My custom style works fine for controls created at design time, but I'm apparently missing something from the picture.

After some trial and error, I did manage to come up with a solution that pretty closely replicates how text formatting worked in VCL. This obviously isn't ideal, but at this point, I will take what I can get and be happy to move on. The trick is to turn off the FontColor in your object's StyledSettings.

//Make ValueLabel to display output
TLabel * ValueLabel = new TLabel( this );
ValueLabel->Parent = VerifyMappingsScrollBox;
ValueLabel->Position->X = ValueLabelLeft;
ValueLabel->Position->Y = LabelTop;
ValueLabel->Width = ValueLabelWidth;
if ( OutputValue.Length() == 0 )
//Turn it light gray if empty
  ValueLabel->StyledSettings = ValueLabel->StyledSettings >> TStyledSetting::FontColor;
  ValueLabel->TextSettings->FontColor = claLightgray;
  ValueLabel->Text = "Empty";
  ValueLabel->Text = OutputValue;

So far, I'm not too impressed with the FMX framework. It does some cool things, but some elements are so buggy and counter-intuitive that it's easy to see why no one is making new documentation or tutorials for it. Which is a bummer for those of us who are obligated to use it for the foreseeable future.

Tuesday, May 13, 2014

Valid NPI Number Generator

If you're in the health care industry, you might be familiar with the term National Provider Identifier (NPI). This is a number used to identify medical providers in many various systems, including the SureScripts network.

The thing about NPIs is that you can't just throw any 10 digits together, as you can for many dummy data elements (such as SSNs).

Here's a handy piece of JavaScript for helping you to generate the appropriate check digit for your NPIs. Just another reminder that other people have probably already solved most of the problems I encounter. :-)

Wednesday, May 7, 2014

JavaScript Odometer Image Generator for Blogger

I looked around a LOT for a simple web app that would allow me to generate an odometer based on simple numeric inputs. Since I didn't find any, I decided to be like the Little Red Hen and make one myself.

It's not very fancy and doesn't have a nice UI or anything, but it gets the job done. If you have a Blogger blog, you can paste this into an HTML / JavaScript gadget and just change the variables in the "mileage" array to change the numbers that display. 

Here is the javascript I used to accomplish this:
<div id="odometer"></div>

//enter additional mileage in this array:
  var mileage = [ 136, // 04/05/2014
77.5, // 04/12/2014
259, // 05/03/2014
0 ];
var miles = 0;

while (mileage.length > 0)
miles += mileage.pop();

var totalmiles = miles;

    //handle weird floating point issue   
    totalmiles = Math.round( ( totalmiles + 0.00001 ) *       10 ) / 10; 
miles *= 10;

var digits = [];
var divby = 1000000;
var dig = 0;

while (divby >= 1)
dig = Math.floor(miles/divby);
miles %= divby;
divby /= 10;

var bdigits = [ "",

var wdigits = [ "",

var borderimg = "";

var outputHtml = "<img height = '32' title = '" + totalmiles + " miles' src = '" + borderimg + "'/ >";

for (var x=0; x<digits.length-1; x++)
outputHtml += "<img width = '20' title = '" + totalmiles + " miles' src = '" + bdigits[digits[x]] + "'/ >";

outputHtml += "<img width = '20' title = '" + totalmiles + " miles' src = '" + wdigits[ digits[digits.length-1] ] + "'/ >";

outputHtml += "<img height = '32' title = '" + totalmiles + " miles' src = '" + borderimg + "'/ >";

document.getElementById("odometer").innerHTML = outputHtml;


Thursday, April 10, 2014

Need to View Files from your Chrome Cache? Here's a Solution!

Here's a great solution to a problem that I was about to solve the hard way. I was trying to retrieve some images (just the images) from a web page I had visited in Chrome.

(They were wrapped in a design that wouldn't allow just right-click, then save as. And, yes, I had a good reason for needing them... it's a long story regarding my church's flaky web provider.)

In Chrome, if you type "about:cache", it brings up a list of the files the browser has recently loaded. When you click on them, though, you see a large HTML file with a hexadecimal code in the body. This is true even for binary files like .jpg or .png.

Senseful Solutions has posted a great little tool for translating the hex back into pages (or, in my case, images): Viewing Chrome cache (the easy way).

This is what programming is all about: making people's lives easier by creating elegant solutions to everyday problems.