HOME - - - - - Lazarus Tutorials TOC - - - - - - Other material for programmers

Be organized or be unproductive

Programming in a GUI world is not easy
Don't give yourself extra ways to be confused

Use folders to organize your work

filename: lt0Nb-folders.htm

This page is "browser friendly". Make your browser window as wide as you want it. The text will flow nicely for you. It is easier to read in a narrow window. With most browsers, pressing plus, minus or zero while the control key (ctrl) is held down will change the texts size. (Enlarge, reduce, restore to default, respectively.) (This is more fully explained, and there's another tip, at my Power Browsing page.)

I am not by nature an organized or disciplined worker.

But when it comes to programming, I have to be organized and disciplined, or I get very little done.

Intelligent use of folders (aka "directories") is an enormous help to me in organizing my work.

I'm sorry to inflict this now...

I recommend this essay very early in my Lazarus tutorials, and I am sorry to trouble you with a slightly complex subject when you are just getting started, but it really is "necessary".

You will probably struggle a bit to understand all that I am saying. Do the best you can. And revisit this essay from time to time as you become more familiar and proficient with Lazarus. Things that are hard to follow now will make better sense later. But getting to grips with other things will be hindered until you grasp what is here. It is one of those "chicken and egg" things.

Three main folders

You will, if you take my advice, have three main folders for your Lazarus work. (At least one of them will have many many folders in folders, and folders in folders in folders... etc... like a hall of mirrors.

When I put it as I just have, it might seem a bit overwhelming. But using my system is actually much simpler than it may sound to you at the moment. My system lets you divide and conquer your work.

My system lets you think about one thing at a time, but even as you do that, "the big picture" can be reasonably clear in your head.

The first two "main folders"

I should say more about these... especially the second... but I get so little feedback or "likes" and such in forums, on social media, that I wonder how many people even read them?

The first "main folder" is the one you install your Lazarus IDE in, when you first set yourself up for Lazarus programming.

Wherever you put it, I would recommend that you do as little as possible within it. Keep this folder JUST for what the nice people at Lazarus and FreePascal have done for us.

It seems that every time I install something, Microsoft has changed the rules. In any case, if you have to migrate to a new machine, you should probably do a fresh install of things like the Lazarus IDE.

So put as few of your "personal tweaks" to these things in the folder of their main "engine".

But of course, you are not just in thrall to Microsoft (Or Apple, or the people behind your Linux), there's also the "things" that the providers of "Lazarus" do to... did I mean for?... you.

I would LIKE to be able to have multiple versions of things like Lazarus on my system.

ANYWAY... The last time I installed the Windows version of Lazarus, it ended up in...

C:\Users\[[my user ID]]\Documents\Prgms\3rdParty\LazSys

... but somehow the Windows menu system held...

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Lazarus19406

That "19406" is a datestamp (6th of April, 2019). While not as good as the version ID of my Lazarus IDE, it does at least put me in with a chance of, when it becomes necessary, having a second, separate Lazarus installation on the PC in question.

BUT ALL OF THAT IS NOT A MAJOR CONCERN! Install your Lazarus somewhere, anywhere... but then try to LEAVE THAT FOLDER ALONE. Let Lazarus do what it wants inside it. But anything you do, in particular, any code writing you do: Do it under a separate main folder.

Second "main folder"

I hope it won't concern you for a long time to come, but eventually you will want to install "libraries" created by others.

You may have noticed I called Lazarus itself a "3rd party" package? It is "3rd party" in that it didn't come from Microsoft or from me, hence "3rd party" there.

You can... but I wouldn't recommend it to a novice... add extra "libraries" to Lazarus. If you do that, it gains extra features, with very little knowledge needed on your part.

For add-ons to the add-on... i.e. libraries to extend Lazarus... I would suggest a main folder for the things you are adding from a different "3rd party"... different from the 3rd party that supplied you with the Lazarus IDE.

It can be a bit of a chore to "tell" Lazarus "about" where to find the enhancements the libraries will provide. But it can be done.

(And of course, within this second main folder, you have sub-folders, one for each "3rd- 3rd party" library. If you adopt this system, then when you have to migrate to a new PC, it will be much easier. And the day WILL come. Sorry, but you know it will.)

The last (third) Main Folder... the one I most wanted to talk about.

So! You are putting the Lazarus IDE in one place. Add-on libraries in another.

The third "main folder" is for your projects!!.

I write programs (applications) in several languages. And, doomed to Windows as I am, I like to have everything that I control under the "Documents" folder.

So, within "Documents", I have a folder called "Prgmming". Within that I have a folder called "Lazarus"

And within that, many, MANY folders... one for each program (aka, in my usage, application) that I've written.

I promise not to go very far down the rabbit hole of how I name my programs, but I will just touch on that before getting back to the main story.

There was a time when names needed to be VERY short. It is still helpful to keep them reasonably short. (Hence my use of "Prgmming" vs "Programming" a moment ago... the folder names in the path leading to a single file are part of "the name" in some contexts where "keep it short" is relevant.

Almost all of my programs have mysterious names like lt001, fm023, ds142

Those would be...

A detail: The number. Decide at the outset... will you have more than 99 programs in this category? If in doubt, say, "I might". And then, with the first programs in the category use leading zeros in the name, as you see above. I took a chance, decide that I wouldn't do more than 99 programs for 1-Wire chips... but such parsimony with zeros usually comes back to haunt me.

Onward...

So... back to the main story...

Recap: We have three main folders for Lazarus. We've dealt with the first two. We've started to talk about the one where your work goes.

(If the division isn't entirely clear, consider this: You have an office suite installed on your PC. (I like Libre Office.)

The software that lets you, say, write a letter, is "somewhere" on your machine. Someplace more of less "hidden", I hope. It will entail hundreds of files. You really don't want them "in your face", on a daily basis. And if they are "hidden", there is less chance that you will Do Something and break the system.

So... you DON'T know where your office suite's programs are, but you DO know where to find the copies you saved of letters you've written.

That's all I'm talking about here. The stuff that makes Lazarus work is "hidden". The stuff you've written WITH Lazarus is in the folder I'm talking about now.

But!

A Lazarus program is a bit more complex than a mere letter! It will involve many files.

With letters, you might use folders to divide and conquer.... you could have one folder for "business" letters, and a separate folder for letters to friends.

For Lazarus you need to set up a folder for each program (application) that you write.

Folders in folders...

We're almost done! But we've come to a bit that's easy to miss, so go get that cup of coffee. Come back alert...

In your folder for your Lazarus work, for the programs you will write, you have one folder for each program.

Let's say I was going to write another text manipulation program... number 143 it would be at this moment in time. And let's say that it is to count the frequency of letters in a big text file. (That, by the way, makes a good beginner's exercise. And the information it would extract does have its uses (even if they are a bit... arcane?))

In whatever you've called your "MyLazarusProgramming" folder, you'd make a folder called...

tm143-CountLetterFrequency

(Yes... I've been a bit profligate with the length of the name of that folder. I am "spending" a little of the room for maneuver that I built up for myself by being careful elsewhere.

AND WITHIN THAT.... we create ANOTHER folder...

tm143

THEN we start up Lazarus, start our program, and very early on we save what we've done so far. (I normally start each program by putting a "Quit" button on the main form, and then I do the first "save".)

Be careful about how you launch the "save". Don't do anything "clever". Either use Ctrl-S, or the menu's File/ Save, or the "floppy disk" icon on the toolbar, narrow red band, white band, blue band with a gray rectangle in it.

The first save does a few "extra" things that don't (normally) arise again in a given project's life.

First it asks WHERE you would like to save the project. Don't be fooled! The process looks very like merely saving, say, a letter. But much more is going on that would be happening if you saved a letter. More is going on even than what will happen from now on when you are saving your work so far on the Lazarus program you have just started.

You can, if you look, tell that you are saving the project. There are at least two indications:

The title of the dialog is "Save PROJECT..." (my caps, for emphasis), and...

The proposed file name has the ".lpi" extension. (Lazarus's grandparent, Delphi) uses a different extension, by the way, if you happen to be working with that IDE.)

So... as I was saying...

Early in the course of a new program's life, do your first save.

Start by moving to the equivalent of...

.../MyLazarusProgramming/tm143-CountLetterFrequency/tm143

REMEMBER: There are TWO folders with names starting "tm143", one of them inside the other.

(You can create the necessary folder within the Save dialog, if you haven't set them up ahead of time.)

... And call the project "tm143.lpi". (You can leave the ".lpi" off... because, just under where you specify the name, the dialog is telling you that it will save it as an .lpi file.)

Then, perhaps alarmingly, until you get used to it, a second Save File dialog will pop up.

Superficially, it looks just like the one you just used!

But this is doing something different... note the dialog's title bar, and the "Save as type", and the default name's extension...

This is saving your source code. Yes! I know! You haven't written any yet! But Lazarus has created a "shell", a "skeleton" of source code. In Pascal terms (Lazarus is founded on Pascal) the "source code" lives in a "unit".

When the second save starts, you should find yourself in the same folder you saved the project file in. And you should save the unit as "tm143u1.pas". The "u1" stands for "unit 1".

Penultimate "last thing"...

So! We have two folders with tm143 in their names. (One inside the other)

We have a file called "tm143.lpi", and one called "tm143u1.pas".

Very early on in my work on your program, I would change the name of the program's form to tm143f1. ("f1" for Form 1"... you got that, right?)

And finally... Backing up your work... And a BIG "don't do it" warning...

You need to back up your work... frequently. Beginners in particular need to do this. Projects will frequently just go completely awry. Do you really want to go all the way back to Square One, regularly? Do a back-up every so often, and you only need to backtrack a little ways.

You don't even have to shut down what you are doing in the Lazarus IDE to do the following...

Go into the operating system's ordinary file management utility. (In Windows once called "Windows Explorer", which was much too close to "Internet Explorer". Since Win10 came along, "File Explorer". Perhaps the one good thing about Win10. Harumph.)

Drill down to the equivalent of...

tm143-CountLetterFrequency

... i.e. the one holding...

tm143

... the folder that has LOTS of stuff in it... stuff put there by Lazarus. (tm143.lpi, tm143.pas, a folder called "backup"... which you LEAVE ALONE, it is NOT "your" backup!), etc.

Right-click on that FOLDER. Select "copy"

Then right-click someplace "blank" in the "tm143-CountLetterFrequency" folder, select "Paste" That will give you a new folder...

tm143-copy

Rename that along the following lines. There Are Reasons for the things that may seem odd.

tm143BU[[date]][[-time]]

"BU" for backup

For [[date]] I would ALWAYS use FIVE characters...

The [[time]] part is optional, but if present, should be separated from the date by a hyphen, and use FOUR digits, but no colon. 8:07am would be 0807. 8:55pm would be 2055.

When you've made your backup, you can just go back to what you were doing in the Lazarus IDE.

DO NOT "mess", by hand, with the stuff inside the "inner" "tm143", i.e. stuff in the folder in the "tm143-CountLetterFrequency" folder.

Exceptions to the "do not mess" rule: You can... and probably should... add text files inside the inner folder. Use them to make notes on how the program works, things still to be done, etc. (In addition, of course, to notes about the same sort of things in rems inside the program's source code.)

Just don't mess with things Lazarus has made.

But you can...

But you can "do things" with the "inner" "tm143"... AS LONG AS...

You might need to do things with the folder "tm143" if you need one of your backups.

To go back to an earlier version, proceed as follows... Don't, by the way, try to "memorize" this... figure out the logic, and remember that.

As I said: FIRST shut down Lazarus.

Then rename your current "tm143" folder something like "wentWrong20412-0815tm143"

Right-click on the most recent backup that seems a good place to go back to.

Choose "Copy"

Right-click someplace "blank" in the "tm143-CountLetterFrequency" folder, select "Paste". Rename the result as "tm143".

Presto! You're back to where you were when you made the backup! And you even still have the back-up that you are using to save you bacon, so if goes astray again, you still have the version that was working when you did the back-up.

Quick note about back-ups of back-ups.

Of course, it isn't just your Lazarus work that needs backing up, is it. (Although Lazarus work entails extra reasons to do backups.)

And are all your backups on your PC? What if the hard drive fails? What if your PC is stolen?

External, USB-connecting, hard drives cost very little, considering how valuable a back-up is. And for really important stuff, have two! Do a full copy of your files, and ask a neighbor to put that hard drive on a high shelf for you. People do get burgled. People do have fires. Use the other drive for 2ndry copies of BUs for a while, until the copy at the neighbors gets "stale", then swap them over.



I hope you never have cause to say "I wish I'd used a system to create back-ups."

If not, you will be the first person to use a computer for more than a year who hasn't. I hope that the essay you've just read will help you have only small regrets when Mr. Murphy "get" you.





Search across all my sites with the Google search...

Custom Search


To search THIS site.... (Go to my other sites, below, and use their search buttons if you want to search them.)

index sitemap advanced
search engine by freefind

Site Map    What's New    Search

The search engine merely looks for the words you type, so....
*    Spell them properly.
*    Don't bother with "How do I get rich?" That will merely return pages with "how", "do", "I"....

Please also note that I have two other sites, and that this search will not include them. They have their own search buttons.

My SheepdogSoftware.co.uk site.

My site at Arunet.


Ad from page's editor: Yes.. I do enjoy compiling these things for you. I hope they are helpful. However... this doesn't pay my bills!!! Sheepdog Software is supposed to help do that, so if you found this stuff useful, (and you run a Windows or MS-DOS PC) please visit my freeware and shareware page, download something, and circulate it for me? Links on your page to this page would also be appreciated!
Click here to visit editor's freeware, shareware page.

Link to Lazarus Tutorials main page

To email this page's editor, Tom Boyd.... Editor's email address. Suggestions welcomed! Please cite "lt_0Nb-folders.htm".




Valid HTML 4.01 Transitional Page has been tested for compliance with INDUSTRY (not MS-only) standards, using the free, publicly accessible validator at validator.w3.org. Mostly passes.

AND passes... Valid CSS!

If this page causes a script to run, why? Because of things like Google panels, and the code for the search button. Why do I mention scripts? Be sure you know all you need to about spyware.

....... P a g e . . . E n d s .....