Monday 21 April 2014

Writing a StrPix-like program with Lazarus – 3

Create a folder somewhere on your PC for your Lazarus projects. I named my folder Typhon32 Projects.

Extract the WadExplorer source code zip file and copy the folder into your Lazarus projects folder.

Do the same with the other source code zip files you downloaded. With the StrPix code you need to also unzip the shared folder inside the StrPix folder.

image




Now save the new project you have open in Lazarus. If you closed it, go to the Project menu and select New Project. In the dialog, select Application and press OK.

Go to the Project menu and select Save Project As. Navigate to the Lazarus projects folder you created earlier and create a new folder inside it for the project then save the project. Take care picking a name for the project since the project name is used as the program name.

You will also be prompted to save the unit file. I always leave it as the default (“unit1”) but other programmers use the name “main” since this unit will be the program’s main form (window).

ProjectFolder


ProjectSaved

By default Lazarus creates new projects in debug mode configuration. To also check for memory leaks in your program while debugging go to the Project menu and select Project Options.

In the dialog select Compiler Options > Debugging and click the checkbox next to “Use Heaptrc unit (check for mem-leaks) (-gh)”

Heaptrc

Now when you close your program a dialog will notify you if all memory was freed or not.

UnfreedMemory

A Lazarus setting I like to disable is using the middle mouse button to paste text. My middle mouse button is a wheel and often when I scroll through the code I accidentally click the wheel button and paste text wherever the cursor is which can mess up the code.

Go to the Tools menu and select Options. In the dialog select Editor>Mouse>Advanced. In the right pane under All select Text. Scroll through the list until you see Quick Paste Selection and then double click that row. In the Edit Mouse dialog Action dropdown box  change Quick Paste Selection to No Action and press OK to apply the change. Press OK in the Options dialog to apply all option changes and return to Lazarus.

NoMiddlePaste

By default Lazarus has many separate windows for its user interface. With the CodeTyphon version you can dock these windows into one. Click on the pale yellow bars displayed in the windows and drag to other windows to dock them. In the Windows menu you can restore the default layout or save and load your own custom layout.

Docking

It is a good idea to use version control software when developing a program. Version control is basically about keeping backups of your code so you can return to an old version of the program. If a program no longer compiles or functions correctly after adding or modifying code you have “broken” the program and sometimes it is best to go back to an old version and try again. I will discuss how to use version control with Lazarus in a future post.

We have now finished the preliminaries and can start creating our program.

prev | next

No comments:

Post a Comment