Categories
Tools

Pretty Printing Your Source Code

A picture is worth a thousand words, but how do you include source code in a presentation? By text or by image?

Nick Hodges asked about this on Facebook the other day.

Here are some of the suggestions from the community (with my commentary), followed by a few of my suggestions.

  • Robert Love suggested Slides.com – it is a paid web based presentation service centered around web standards. It includes built in features for making your code snippets look nice. Pro: Includes the code as text. Con: One more monthly fee (there is a free plan).
  • Glenn Dufke suggested pasting the code with Syntax Highlighting preserved – By default the RAD Studio/Delphi IDE doesn’t maintain this, but the GExperts IDE Plugin has a Source Code Export expert (I used to use this). I’m sure there are others (CnPack maybe?)
Source Export
GExperts Source Export Export
  • David Schwartz suggested just doing a screenshot from the IDE – this preserves your artistic view of how you have your IDE configured. Downside is the code can’t be easily extracted from the slides . . .
  • Bruce McGee suggested reveal.js – I’ve not used it yet, but it is a full web standard presentation framework, and looks promising. It uses highlight.js for the syntax highlighting, which I have used. With support for 185 languages, it has you covered. I’ll certainly be checking that one out. Thanks Bruce!

Now for my suggestions. In the past I’ve used the rich export options like Glenn suggested, colorized the text by hand, or used an intermediary like Notepad++, etc. But here are some options specifically around creating code screenshots.

Greenshot – is my current preferred desktop screenshot tool for pulling images directly from the IDE. It includes a nice editor for your screenshots too, so you can quickly annotate them, blur things out, etc.

Greenshot screen shot image editor

Carbon.now.sh is a web page that takes your code and converts it into a nice image with a macOS style window. There are a few customization options. If you embed it or share it via URL then it provides both the source code and the preview. It doesn’t list Delphi as a language, but the Pascal support is close enough.

Sample from Carbon.now.sh

Codeimg.io is similar to Carbon, but has more configuration options. The best part is that you can use templates sized exactly for different social media platforms. A lot more customization options, including both Windows and macOS window styles. It doesn’t appear to offer a share by URL or embed option, and only does the image generation. For some reason it defaults to a JPG instead of a PNG for the image though (also supports SVG). Newer addition and still in beta.

Codeimg.io

src2img is a no-nonsense straightforward converter that turns out Source into a PNG file. Just select language (auto detects Delphi) and style. It is based on highlight.js and the source is on GitHub. Doesn’t offer a link share, just image download.

Instacode is the Instagram of the bunch, with image filters like tilt shift and 3D rotation. Directly supports Delphi language, and you can share via a URL that allows someone to access the code and remix the image. Even has wallpaper generator.

Image result for photoshop logo

Lastly, if you have some Photoshop skills (or can follow tutorials like I do) then you can make your own. This is a combination of screenshots, with perspective warps, a few filters, background images, etc.

Did I mention CodeRage 2019 is coming soon?

How do you pretty print your source code? Which of the above is your favorite, or what did I miss?

Categories
Source Code Tools

Use the Source!

One of the great things about Delphi is not only is it written in Delphi (mostly), but it ships with the VCL, RTL, & FMX source code. You can use this source code in lots of different ways, which I’ll cover in a bit, but sometimes it is a matter of finding the source file with the code you want. There are over 2,234 Delphi source files in the source folder, so it can take a while to find the right file if you don’t know where to look. Not to mention the 1,711 C files, and a few thousand other assorted files.

Source Folder Files

I used to use various GREP and full text searching tools to find the code I was looking for, but then I realized Windows 10 (and earlier versions) has a search function built into it, but you need to make a few configuration changes to use it effectively. So I thought I would outline those for you.

Your source folder is usually located in
C:\Program Files (x86)\Embarcadero\Studio\19.0
but it might be different depending on your installation. I usually Pin it to Quick Access, which makes it easy to access since I find I’m there a lot.

Source Folder

Windows Search and Indexing Options

The next thing to do is configure your Indexing Options. This is what makes it quick to search for files you need. You can find Indexing Options in Control Panel, or just runcontrol.exe srchadmin.dll.

control.exe srchadmin.dll

There are two steps to get the most out of Windows search for your source code. The first is you need to activate Windows search for the file extensions you want, and the second it to tell it to index your folders.

Indexing Options

To add PAS files to indexing click Advanced and go to File Types. You can just type PAS in the list of file types and it will find it for you. You don’t need to add a new extension. PAS files are already listed, but just not indexed by default. Just put a check next to it, and change the “How should this file be indexed?” to “Index Properties and File Contents” that will index all the text contents of the file

Indexing File Types

By default all your user folders are indexed, but Source is in your Program Files folder, so you need to explicitly add it. From the main Indexing Options window click Modify and from there you can add any folder you want to search.

Indexed Locations - Source

It takes a while a while to build and update the index after this change. You just gave it 2,000 more files to index. It has to read all the text out of them, which takes a while. Once it is done then just go to your source folder and use the search box to quickly find the code you are looking for.

Search Results

Everything Search

Everything Software IconAnother great tool to use, to search by file name is the Everything desktop search engine by Voidtools. The thing I love about using Everything is it searches all the file names on your system quickly. The difference between it and Windows Search is Everything only searches the file names, but it searches all the file names.

Everything Search

I find I usually remember the name of a file, but not exactly where I left it. This makes Everything indispensable for me.

Using the Source

So how useful is it that Delphi, RAD Studio and C++Builder includes all this source code? What all can you do with it?

  • Finding that function – You know how I said I can remember the name of a file, but not where I put it? I do the same things with classes and functions. I can remember the name of the method or class, but not which unit it is in. Being able to search all of the source instantaneously to find the source file you need is a huge help.
  • Learning – Just reading source isn’t the best way to learn to program, but having access to the source code is a great way to gain a deeper understanding.
  • Debugging – Sometimes your program doesn’t behave the way you expect it to. When all you have is a blackbox then you are unable to figure out what is happening behind the scenes. When you have the source code you can not only see how that method is implemented, but also debug into the source code, using all the great debugger features.
  • Adding New Features – Maybe there is a new API that was just released, or you need to access an obscure API or 3rd party feature. Since you have access to all the source you can see how other similar APIs are accessed and use that as a roadmap.
  • Fixing or Changing Functionality – One man’s bug is another man’s feature. Sometimes there are bugs you need to fix in the shipping source code, other times you just want to change the way things work. For small changes I just copy the source file out into my project directory. Then my code will use my modifications instead of the original implementation. While you can’t redistribute changed source code, you can compile the code into your program. If you do need to share your changes or fixes you can share a change-set that only contains your changes.

What else do you use the source for?

Categories
Tools

Creating a Bootable USB Drive on macOS from an ISO

Creating a bootable USB drive from an ISO is pretty easy on Windows, but you end up going to the terminal on macOS. Not a big deal if you remember all the commands. Since it seems like I’m frequently installing something (Linux, Windows 10, etc.) on a different I thought I would make a quick blog post listing the steps for next time.

  • First convert the ISO into a disk image for macOS.
  • Then rename it to .img
  • Use diskutil to find the target USB drive
  • Unmount the USB drive and write the img file
  • Eject the USB drive
hdiutil convert -format UDRW -o targetfile.dmg sourcefile.iso
mv targetfile.dmg targetfile.img
diskutil list
diskutil unmountDisk /dev/disk4
sudo dd if=Desktop/targetfile.img of=/dev/rdisk4 bs=1m
diskutil eject /dev/disk4

I usually get an error from macOS when I’m done about not being able to read the USB disk. It is also fairly quick too.

Categories
REST Source Code Tools

FireDAC MemTable Editing – New in 10.2 Tokyo

One of my favorite new features (beyond Linux) is the ability to edit the data in a TFDMemTable at design time. You could already edit the field defs, to set it up. This makes the TFDMemTable, which was already super flexible and powerful, even more flexible. You can use it to capture some small data at design time and then use visual live bindings or data binding to connect it to visual controls.

Edit TFDMemTable

Holger Flick has a great blog post on the topic too. Here is a video I made with Sarina that shows it in action.

What is your favorite new feature in Tokyo?

Categories
News Tools

Delphi Tokyo 10.2 Wallpaper

I’ve had a few requests for my Delphi Tokyo 10.2 wallpaper that I made. I found out that while this is a picture of Mt. Fuji in the background, this photo is from the Kyoto side, not the Tokyo side. I got the photo from Pixabay, which is a great free clip art site. They have many more Tokyo, Japan and Mt Fuji themed images if you want to make your own wallpaper.

Delphi Tokyo 10.2 WallpaperI purchased the sunglasses wearing spartan penguin from a different clipart site. The tattoo and scary eyes came from our internal creative team. I forget which one, but I’ve gotten a lot of mileage out of him. You can download my Photoshop file for this wallpaper if you want to tweak it.

Here is another collection of logos I put together for the T-Shirt contest. Pixabay also has pictures of speed, power, and success. I especially like this one:

Code Monkey Need BananaWhat terms do you use to describe Delphi, C++Builder, RAD Studio and the new 10.2 release? I’d love to see your wallpapers too!

Categories
News Request for feedback Tools

#ILoveDelphi How About You?

#ILoveDelphiFebruary 14th is Delphi’s birthday (and some other holiday). What a great time to talk about how much we love Delphi.

I moved from Basic to Turbo Pascal back in the DOS days, and then started using Delphi with version 2. Since then I’ve used a number of other development tools, including Objective-C, Java, JavaScript, C# and others. Delphi has always been my favorite. It is the tool I turn to when I need to get something done quickly, and it is the bar which I use to measure every other development tool (and none of them measure up).

My son took a class in JavaScript through school. He was really frustrated with it, and wanted to give up programming. I told him I’d be happy to sit down with him again and teach him Delphi (I’d done it a few times in the past, but he lost interest). He reluctantly agreed. After a few minutes he was blown away. All the major frustrations he had from JavaScript was alleviated right away. Soon he created a mobile app that was useful and solved a problem for him in one of his games. He was telling his mom about how much better Delphi is than JavaScript when he said “No wonder everyone loves Delphi, it is the best!”

What about you, why do you love Delphi? Create a video, a blog post or whatever works for you, and share it with the hash tag #ILoveDelphi.

Categories
Article News Tools

More on 1Password’s Components

Stefan van AsStefan van As of 1Password fame sent me a more exhaustive list of the libraries and tools used in 1Password. I thought I would share it with everyone. He also recently started blogging about security, software development and Delphi.

Here is an overview of the 3rd party components used in 1Password:

  • 1PasswordBrowser Helper Objects (BHOs) — this is what powers 1Password inside Internet Explorer.
  • Bonjour — this is what powers Wi-Fi Sync. (here is an unrelated Delphi
    implementation
    )
  • ChilkatCrypt — this is what powers some of our crypto
  • MS Crypto — this is the Pseudo Random Number Generator (PRNG)
  • DISQLite — Some of 1Password’s features – such as Watchtower, for example – are utilizing SQLite. Because 1Password 4 is in Delphi 2007, we use DISQLite for that (today, it would be using FireDAC for that)
  • dxgettext — this is used to localize 1Password. It works nicely with Crowdin, a localization project management platform
  • GraphicEx and Graphics32 — this gives (alpha channel) transparency
  • HyperString — super fast string handling routines. (no longer available)
  • OpenSSL — this is what powers PBKDF2 (among other crypto routines)
  • sgcWebSockets — The WebSockets are used with the Chrome and Firefox browser extensions
  • StreamSec — another crypto library, mostly for SSL/TLS
  • zlib and LibTar — for OS X-compatible compression routines

Also uses the following tools:

A lot of great tools and libraries there.

Categories
News Tools

10 Reasons to Use PAServer for Remote Windows Deployment

Everyone knows PAServer (Platform Assist Server) is the easy way to deploy and debug multi device apps from Windows to Apple OS X and iOS. It handles all the bundling and deployment from your Windows development platform across the network, via a virtual machine, or even to the cloud.

Previously I showed you how to connect to a Android Emulator on another machine (or outside your VM), but did you know you can also use the PAServer to deploy and debug against a remote Windows machine? It isn’t required, so isn’t as immediately obvious, but it is supported and pretty easy to setup.

If you are already developing on a Windows machine, why us PAServer to test against a remote Windows machine? There are a lot of reasons, here are a few . . .

  1. Testing on machine without IDE installed
  2. Windows tablets
  3. Different CPU architectures (64-bit vs 32-bit)
  4. Different numbers of cores
  5. Utilizing specialized hardware
  6. Running outside / inside a virtual machine
  7. Deployment on a server (remote, local, in the cloud)
  8. Debugging on more than one version of Windows
  9. Debugging issue that only occurs on one machine
  10. Bundled deployment options

Now that we see the need, how do we do it?

Install PAServer on the target Windows computer. You can find it at C:\Program Files (x86)\Embarcadero\Studio\17.0\PAServer if you used the default install location during your original install. When installing PAServer, you either need to use a different install location (to a user writable folder), or specify a custom scratch-directory, as the default is not writable (unless you run PAServer as Administrator) and will give you an E0009 PAClient Error. Once PAServer is setup just run it.

Custom PAServer Install Destination

Use the Connection Profile Manager to create a new Windows profile.

RAD Studio Connection Profile Manager

Instead of the default of OS X, choose either Windows 32-bit or 64-bit. The rest of the configuration is the same.

Create Windows 64-bit Profile Connection

Then form the Project Manager, right-click on the Windows platform you want to deploy remotely, and select properties.

Project Manager - Platform Properties

And then select the new connection you want.

Platform Properties - Select Profile

This works with any project type (FireMonkey, VCL, Console, etc.)

Profile Selected

Now you can also use the Deployment Manager for Windows apps as well.

Categories
REST Tools

Delphi and REST Client Development

I really don’t like to make comparison between different development tools. In my opinion most tools have their strengths for certain tasks. So I try not to criticize other tools by name. Delphi is my favorite, and I believe it is the best all around tool for more projects I face. Occasionally I have someone ask me how Delphi compares to another tool they are evaluating. I thought I would share one such experience.

When I was in Brazil I went to meet with a guy who was in charge of software development for a large, international company. They were all standardized on a different development tool, but it didn’t really have a mobile solution. They were looking at some tools that claimed to make it really easy to do mobile development, but once he got past the marketing he found it wasn’t all it was cracked up to be.

To evaluate the tool he decided he would develop a simple little app for iPhone and Android that connected to a REST server to pull down a list of countries, cities, etc. to help people find offices for his company. He thought that a week should be more then enough time to develop this simple application.

What he found was that while he expected it to be cross platform, it was actually only shared code. So he had to create a project for each platform, and then he could share part of the code (not as much as he would like) between each project. Also there was significant overhead in consuming a REST service. After a couple days he realized a week wasn’t enough time for even one platform.

To top it all off he discovered that the cost was actually way more then it was initially made out to be when you actually got down to doing something serious.

So I showed him Delphi and told him that the app he was describing could be done inside a day, probably with a prototype within an hour. He found that a little hard to believe, so I created a simple REST client displaying the result of a REST service and deployed it to my Android phone. It took about 5 minutes, including the time it took to connect to his WiFi.

He was so impressed he actually got his phone out to make a video of it just so he could show his boss, who he was sure wouldn’t believe him.

That is what I love about Delphi. It makes the simple things that you need to do all the time so simple and so quick, and it makes everything else still pretty simple. Need an API that isn’t wrapped in a component or the RTL, no problem, you can still access it.

Categories
DataBase REST Tools

Export Trello to CSV

I’m a big fan of Trello as a way to organize and collaborate. Recently I needed to export a Trello board to CSV. They have an export to JSON, but you have to buy a years worth of business class for the export to CSV. The business class is probably worth it for other reasons as well, but I thought I would see what it would take to convert JSON to CSV using Delphi 10 Seattle’s REST Client and FireDAC. I’m really pleased with what I came up with, and it didn’t take much effort.

I used the REST Client to connect to the JSON export on Trello. The REST Client is overkill for this since it is just a simple HTTP GET request, but the REST Response DataSet adapter is what I was after. This piped the JSON into a TFDMemTable.

Now the JSON from Trello contains a few collections (JSON Array’s of objects) so I used 3 different adapters (each with a different root node) and 3 different memory tables: Cards, Lists and Labels. There are other collections, but I wasn’t interested in them right now.

Once I have the JSON in a DataSet, I need to work with it. So I put down a TFDLocalSQL component and pointed it to the Mem Tables. Then attached a TMemo to the Query of a TFDQuery component, and I was able to run SQL querries against the Trello board. This made it easy to select exactly the data I wanted to export.

For the export I just used the FireDAC ETL functionality to pump the DataSet resulting from the Local SQL query to a text writer which saves a CSV file.  I love the way FireDAC provides all this great high level functionality like Local SQL and the Text Writers. It makes so many tasks so easy to deal with.

There is still a lot of polish to do for this, but right now it does the job really well. I thought I would share it with anyone else who might be interested in exporting Trello to CSV. You could take a look at the source code and use it to convert most any REST/JSON datasource to CSV.

I put the code up on GitHub.