Difference between revisions of "Lazarus Tutorial/nl"

From Free Pascal wiki
Jump to navigationJump to search
Line 183: Line 183:
 
* '''Add editor file to Project''': Voegt het bestand dat in de editor actief is, aan het projet toe.
 
* '''Add editor file to Project''': Voegt het bestand dat in de editor actief is, aan het projet toe.
 
* '''Remove from Project''': Toont een lijst met bestanden die deel uitmaken van het project zodat je aan kunt geven welk bestand verwijderd kan worden.
 
* '''Remove from Project''': Toont een lijst met bestanden die deel uitmaken van het project zodat je aan kunt geven welk bestand verwijderd kan worden.
* '''View Source''': No matter which file you are editing, takes you back to the main program file (.dpr)or the main .pas file if there is no .dpr.
+
* '''View Source''': Laat het "hoofd"bestand van het programma zien. Dit is meestal het project bestand (.lpr).
* '''View ToDo List''':Opens a dialog box with a list of ToDo items associated with this project. This will list any ToDo comments in your project (lines commencing //TODO), and any others in the Lazarus units you have used. You need to Refresh the ToDo items in the dialog (using arrow symbol button of toolbar) before new 'ToDos' appear. The first column of the ToDo list contains numbers you have allocated to your ToDo comments; a simple //TODO comment will appear as a zero, but a comment of //TODO999 (for example) will place the number 999 in the first column.
+
* '''View ToDo List''': Laat een lijst met "ToDo" dingen zien. de lijst wordt opgebouwd uit de commentaar regels die met //TODO beginnen. Je kunt zelf de items nummere door achter //TODO een volgnummer te zetten.
  
 
====The Run sub-menu====
 
====The Run sub-menu====

Revision as of 13:17, 28 March 2005

Inleiding

Lazarus is een "vrije" en open source ontwikkelomgeving die gebruik maakt van de FreePascal Compiler (object pascal). De FreePascal Compiler is ook een open source project en "vrije software". De Lazarus IDE (schermafdruk) is een stabiele en complete ontwikkel omgeving waarmee grafische en terminal programma's ontwikkeld kunnen worden. Lazarus draait onder Linux, FreeBSD, Windows, MAC-OS en ook op 64 bits platforms. Naast een instelbare code editor heeft Lazarus ook een grafische tool voor het maken van de programma schermen, alles volledig geïntegreerd met de FreePascal compiler.

Het begin

(Thanks to User:Kirkpatc)

Je eerste Lazarus programma

Download, installeer en start Lazarus. Voor een complete handleiding voor de installatie van Lazarus verwijzen we naar deze pagina, hier willen we alleen aantekenen dat bij de windows installer FPC automatisch geïnstalleerd wordt en dat je voor Linux FPC, de FPC-sources en Lazarus apart moet installeren. Let hierbij dat de FPC versie past bij de gekozen Lazarus versie.

Nadat je Lazarus gestart hebt, zie je verschillende windows op je scherm: het hoofdmenu bovenin, de "Object Inspector" aan de linkerkant, de source code editor neemt het grootste deel van je scherm in, daar overheen zie je de basis voor je eerste scherm ("Form1").

Het scherm met het hoofdmenu bevat niet alleen een menu, maar ook een aantal knopjes en een rij met "tabs". Als de "Standard" tab nog niet geselecteerd is, doe dat dan door er op te klikken met de muis. Zoek dan de "Button" icon (een rechthoekje met 'OK' erop) en klik daarop. Klik daarna ergens links van het midden op het "Form1" scherm. Hierdoor zal er een rechthoek (een windows knopje) verschijnen met de tekst 'Button1'. Klik nog eens op de "Button" icon op de "Standard" tab en daarna weer op "Form1" rechts van de eerste button. Er zal een tweede knop verschijnen, ditmaal met de tekst 'Button2'.

Klik nu op Button1 om deze te selecteren. In de Object Inspector worden de eigenschappen (properties) van de Button1 getoond. Bovenin de Object Inspector vind je de property 'Caption', deze heeft nu de waarde 'Button1'. Klik in dit vakje en wijzig de tekst in 'Press'. Als je nu op ENTER drukt of in een andere vakje klikt zul je zien dat de tekst op de knop nu wijzigt in 'Press'. Klik nu op de "Events" tab van de Object Inspector, hierdoor zie je een lijst van de verschillende Events waarop door de knop gereageerd kan worden. Deze Events bevatten onder meer OnClick, OnEnter, OnExit. (Events ontstaan als gevold van akties van de gebruiker van je programma. Wordt er op een knop geklikt dan wordt dus het OnClick event aangeroepen.) Klik in het vakje naast het OnClick, er verschijnen dan een knopje met een driehoekje en een knopje met een ellipsis (...). Als je op het ellipsis-knopje drukt, wordt er automatisch naar het editor scherm overgegaan en zal de cursor knipperen in een stukje code dat er als volgt uit ziet:

 procedure TForm1.Button1Click(Sender: TObject);
 begin
 
 end;

Type op de regel tussen begin en end het volgende:

 Button1.Caption := 'Press again'

Druk nu op F12 en je wordt weer terug gebracht naar het ontwerp van Form1.

Wijzig nu de properties van Button2 door er op te klikken en dan naar de Object Inspector te gaan. Wijzig het Caption property in 'Exit'. Ga dan naar de "Events" tab en klik op het vakje achter OnClick, klik dan op de ellipsis knop en je komt weer in het editor scherm. Wijzig de hierbij automatisch aangemaakte procedure zodat deze er als volgt uit ziet:

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

Je hoeft dus alleen maar Close; in te typen.

Je bent nu klaar om je programma te compileren en uit te voeren. De makkelijkste manier is om van het 'Run'-menu de 'Run'-optie te kiezen, je kunt ook op F9 drukken of op het groene driehoekje klikken. In ieder geval zal je programma eerst gecompileerd worden en daarna gelinkt. Uiteindelijk zal je programma uitgevoert worden, als tenminste alles is goed gegaan en er geen fouten in je code zaten.

Er zal nog een scherm verschijnen waarin allerlei meldingen van de compiler zullen verschijnen, maar uiteindelijk zal je scherm Form1 getoond worden (zonder alle puntjes, die je in de ontwerp fase ziet.) Dit is het "mainwindow" van je applicatie en het wacht op de dingen die komen gaan.

Klik eens op de knop met de tekst 'Press'. Als het goed is, zie je dat de tekst wijzigt in 'Press again'. Klik je er nog eens op, dan blijft de tekts 'Press again'!!

Klik nu op de knop met de tekst 'Exit'. Het scherm zal sluiten en daarmee wordt je programma afgesloten. Je komt weer in de IDE, waar het originele Form1 scherm weer te zien zal zijn met alle puntjes. Je kunt dan dus weer verder gaan met het wijzigen van je scherm en je programma.

Het is verstandig (en hopelijk niet te laat) om je werk op te slaan. Dit kun je doen door ctrl-shift-s te geven of in het 'Edit'-menu de keuze 'Save all' te maken. Maak er een gewoonte van om je werk regelmatig op te slaan, zodat je geen werk kunt verliezen!

Een kleine uitbreiding.

Heropen, indien nodig, je opgeslagen project. (Menu 'Project', keuze 'Open recent project') Klik in het "Form1" scherm op de "Press" knop (Button1) om het te selecteren. Ga naar op de Object Inspector en klik op het vakje achter het OnClick. Een klik op de ellipsis knop brengt je dan in de editor in de code van het OnClick event van deze knop. Wijzig de code zodat die er als volgt uitziet:

 procedure TForm1.Button1Click(Sender: TObject);
{We gebruiken hier het Tag property, die de waardes 0 of 1 krijgt.}
 begin
   if Button1.tag =0 then
   begin
     Button1.caption := 'Press again';
     Button1.tag := 1
   end else
   begin
     Button1.caption := 'Press';
     Button1.tag := 0
   end
 end;

Sla je werk weer op, laat het opnieuw compileren en run je programma. Als je nu op de eerste knop drukt, zie je dat de tekst wisselt tussen 'Press' en 'Press again'.

The rest is up to you!

Tekst georienteerde programma's.

Als je een console of tekst georienteerde programma moet schrijven (bijvoorbeeld als je een basis cursus pascal volgt, of voor een programma dat door een batch file wordt uitgevoerd), kun je ook Lazarus gebruiken om dit programma te bewerken, compileren en uit te voeren. Lazarus is dus ook een ideale tool om Pascal programma's te schrijven. Zie Console Mode Pascal.

De Editor

De onderdelen van de Editor

Als je Lazarus opstart, verschijnen er een aantal losse van elkaar onafhankelijke of te wel 'floating' schermen op je desktop.

Het scherm aan de bovenkant van je desktop heeft als titel: Lazarus Editor vXXXXXX - project1. Hierbij wordt de serie X-en vervangen door het versie nummer van de Lazarus omgeving en zal project1 de naam weergeven van het project waar je op dat moment mee bezig bent. Dit scherm is het hoofdscherm en bevat het hoofdmenu en de componenten pallet.

File:lazmain.jpg

Onder de titelbalk zien we het Hoofdmenu, met de gebruikelijke keuze als File, Edit, Search enzovoort. Daarnaast zijn er een aantal keuze specifiek voor Lazarus. Daaronder vinden we aan de linkerkant een aantal knopjes die een snelle en eenvoudige toegang geven tot een aantal belangrijke en veel gebruikte functies. Naast deze knopjes vinden we het componenten palet. Net zoals een schilder gebruik maakt van een palet om een kleur verf te kiezen, hebben we in Lazarus een pallet om een te gebruiken component te kiezen.

Onder dit hoofdscherm zie je aan de linkerkant de Object Inspector, en de Lazarus Source Editor aan de rechterkant. Er kan nog een ander kleiner scherm, genaamd Form1 zichtbaar zijn, dat over de Lazarus Source Editor scherm ligt. Als dit niet gelijk zichtbaar is, kun je het oproepen door op F12 te drukken. De F12 toets schakelt heen en weer tussen een form en de bijbehorende code unit. Het form is de grafische interface van je programma.

Als je een nieuw project start zal er een default Form worden aangemaakt. Dit form is niet meer dan een kaal scherm met titelbalk en op dat scherm een matrix van puntjes die je helpen bij het positioneren van de verschillende componenten. De titelbalk bevat ook de gebruikelijke Minimize, Maximize en Close knopjes. Als je op het form klikt, zie je in de Object Inspector aan de linkerkant van je desktop de properties (eigenschappen) van het form.

Er zijn nog meer schermen die je zichtbaar kunt maken of die zichtbaar worden tijdens het werken: de Project Inspector, die gegevens laat zien over de bestanden die onderdeel zijn van het project; het Messages scherm, waarin compiler meldingen, foutmeldingen en voortgang rapportage getoond worden. Als je Lazarus opstart vanuit een terminal scherm, dan blijft dit zichtbaar en worden de compiler meldingen hierin ook weergegeven.

Het Hoofdmenu

Het hoofdmenu bevat de volgende keuzes: File Edit Search View Project Run Components Tools Environment Windows Help

De keuzes kunnen op de bekende manieren geselecteerd worden, door een klik met de muis of door het gebruik van de Alt toets in combinatie met de onderstreepte latter. De F10 toets zorgt er ook voor dat het menu actief wordt.

Het File menu

  • New Unit: Maakt een nieuwe Unit file aan zonder form (Pascal Source).
  • New Form: Maakt een nieuw Form: Zowel het zichtbare form als de bijbehorende Pascal source file.
  • New ...: Laat een pop-up scherm zien keuzes van verschillende nieuw te maken documenten.
  • Open: Opent een "Open bestand" dialoog om een bestaand document te openen.
  • Revert: Maakt alle wijzigingen ongedaan en keert terug naar de laatst opgeslagen versie van het bestand.
  • Open recent: Geeft uit keuze uit de laatst geopende bestanden.
  • Save: Slaat het huidige bestand op onder de bekende naam. Als er nog geen naam bekend is, zal het systeem hier om vragen. (net als 'Save As').
  • Save As: Stelt je in staat om de file onder een andere naam en of in een andere directory op te slaan.
  • Close: Sluit de huidige file, en vraagt indien nodig of de wijzigingen moeten worden opgeslagen.
  • Close all editor files: Sluit alle files in de editor en vraagt eventueel of de wijzigingen moeten worden opgeslagen.
  • Clean directory: Toont een dialoog waarin een serie van wijzigbare filters getoond worden voor het verwijderen van bepaalde bestanden in de huidige directory. Dit is handig voor het verwijderen van backup files en overblijfselen van oude Delphi projecten.
  • Quit: Sluit Lazarus af, eventueel na het vragen of wijzigingen moeten worden opgeslagen.

Het Edit menu

  • Undo: Draait de laatste actie terug.
  • Redo: Voert de laatste actie die was terug gedraaid opnieuw uit.
  • Cut: Verwijdert de geselecteerde tekst en plaatst dit op het Clipboard.
  • Copy: Plaatst een kopie van de geselecteerde tekst op het Clipboard.
  • Paste: Plaatst de inhoud van het Clipboard op de cursor positie. Als er tekst is geselecteerd wordt deze tekst vervangen door de tekst op het clipboard.
  • Indent selection: Laat de geselecteerde tekst naar een aantal posities inspringen. Het aantal posities kun je instellen via Environment -> Editor options -> General -> Block indent. Dit is een handig tooltje bij het formateren van je source code.
  • Unindent selection: Het tegengestelde van de vorige menukeuze. Het verlaagt het aantal positie dat de geselecteerde tekst is ingesprongen.
  • Enclose selection: Laat een pop-up schermpje zien waarin een keuze gemaakt kan worden voor een bepaalde blok structuur, zoals bijv.begin ... end; try ... except; en nog een aantal. De geselecteerde tekst wordt dan in de gekozen structuur opgenomen.
  • Uppercase selection: Zet de geselecteerde tekst om naar uppercase.
  • Lowercase selection: Zet de geselecteerde tekst om naar lowercase.
  • Tabs to spaces in selection: Zet tabs om naar spatie in de geselecteerde tekst. Het aantal spaties wordt bepaald in Environment -> Editor options -> General -> Tab widths.
  • Break lines in selection: Als er regels in de geselecteerde tekst langer zijn dan in Environment -> Editor options -> Display -> Right Margin is ingesteld, worden deze regels afgebroken op een woord grens en vervolgd op de volgende regel.
  • Comment selection: Maakt van de geseleteerde tekst commentaar door iedere regel te laten beginnen met //.
  • Uncomment selection: Verwijdert de commentaar markeringen.
  • Sort selection: Sorteert lijnen (of woorden of paragrafen) alphabetisch, hierbij zijn opties voor oplopend of aflopend, hoofdlettergevoelig of niet.
  • Select: Hierbij kunnen bepaalde blokken tekst geselecteerd worden. Mogelijkheden hierbij zijn bijvoorbeeld select all, select to brace, select paragraph or line etc.
  • Insert from character map: Maakt het mogelijk om bijvoorbeeld diakritisch tekens in te voeren, door ze in een popup schermpje te kiezen.
  • Insert text: Geeft een popup menu voor het invoeren van bepaalde standaard teksten zoals CVS sleutelwoorden (Author, Date, Header etc) of GPL notitie, de gebruikersnaam of de huidige datum en tijd.
  • Complete code: Complementeert de code waar de cursor staat. Dit is redelijk intelligent en kan je een hoop tijd besparen. Het kan bijvoorbeeld classes complementeren door het toevoeging van "private" variabelen, Getters en Setters en het toevoegen van method bodies. Zie ook Lazarus IDE Tools.
  • Extract procedure: Van de geselecteerde tekst wordt een nieuwe procedure gemaakt.

Het Search menu

  • Find: Net als bij alle andere tekstverwerkers, krijg je een popup te zien waarin je zoekcriteria kunt invullen.
  • Find Next, Find previous: Voert de vorige zoekaktie opnieuw uit in de aangegeven richting. (Next zoekt naar het eind, Previous naar het bein.)
  • Find in files: Het zelfde als Find maar nu kun je ook laten zoeken in alle files van het project of alle bestanden in een directorie.
  • Replace: Vervangt een bepaalde tekst door een andere.
  • Incremental find: Een zoek functionaliteit die werkt terwijl je de zoekstring invult. Bijvoorbeeld: Nadat je "Incremental Find" hebt gekozen en je typt een "l" zal de eerste "l" worden gehighlight. Typ je daarna een "a" dan zal de eerste "la" getoond worden, etc.
  • Goto line: Hiermee gaat de cursor naar de aangegeven regel in de file.
  • Jump back: Gaat terug naar het vorige Bookmark. Dit Bookmark moet eerst met Add jump point to history gezet zijn. Dit werkt door alle in de editor geopende bestanden.
  • Jump forward: Ga naar het volgende Bookmark.
  • Add jump point to history: Plaats een bookmark of "spring"punt.
  • View Jump-History: Dit moet een lijst van bookmarks laten zien. Maar is helaas Not implemented yet.
  • Find other end of code block: Als de cursor bij een begin staat, springt deze naar de bijbehorende end of vice versa.
  • Find code block start: Springt naar het begin van de procedure of functie.
  • Find Declaration at cursor: Toont de plaats waar een identifier is gedeclareerd. Dit kan in dezelfde file zijn, maar ook in een andere file. Als deze file nog niet in de editor geopend is, zal dat automatisch gebeuren. Als de cursor bijvoorbeeld in TButton staat, zal de file buttons.pp geopend worden. (Dezelfde functionaliteit krijg je met een ctrl + muisklik.
  • Open filename at cursor: Opent de file waarvan de naam onder de cursor staat. Kun je bijvoorbeeld gebruiken voor het zoeken van Include files.
  • Goto include directive: Als het actieve bestand ge-include wordt in een ander bestand, wordt dit andere bestand geopend, met de cursor op de plaats van het include directive.

Het View menu

Geeft je de controle over welk van de verschillende schermen op je desktop actief wordt.

  • Object Inspector: Standaard staat dit scherm aan de linkerkant van de desktop. Het toont de eigenschappen van het control dat op dat moment geselecteerd is. Als je dus op een component op je form klikt worden de eigenschappen (properties) daarvan in de object inspector getoond. Bovenin de object inspector zie je een boom-structuur waarin de componenten van het actieve form te zien zijn. Je kunt ook in deze boom-structuur klikken om de eigenschappen van een bepaald component te laten zien. Het onderste deel van de Object Inspector heeft twee tabs. De eerste bevat alle Properties en de tweede alle Events. Onder Properties vinden we de eigenschappen zoals name, colour, caption, font, size.Er zijn twee kolommen. In de linker kolom staat de naam van het property, in de rechter kolom wordt de toegekende waarde getoond. Ook de Events-tab kent twee kolommen. De linker kolom toont de verschillende events die het component kent en de tweede de naam van de aan dat event toegekende procedure. Als er nog geen procedure aan een event is toegekend, kun je dat doen door in het bijbehorende vakje te klikken en dan op de
    ...
    knop te klikken. Je komt dan in de code editor terecht en is er een basis declaratie voor de procedure gemaakt.
  • Source Editor: In dit scherm kun je de source code bewerken. Het werkt in principe net als iedere andere tekstverwerker. De muis kan de cursor overal in de tekst plaatsen en met het links klikken en bewegen van de muis kun je tekst selecteren. Een rechter muisklik geeft een popup-menu. Het popup menu ziet er echter anders uit dan het normale Knip, Kopie en Plak menu dat je gewend bent. Je ziet echter wel opties als Find Declaration en Open File at Cursor. Aan de bovenkant van de source editor zie je een aantal tabs, een voor iedere file die je geopend hebt. Het klikken op zo'n tab maakt de bijbehorende file de actieve file. Je kunt natuurlijk tussen de verschillende files ook knippen en plakken. Je zult zien dat de editor "Syntax highlighting" kent, met instelbare kleuren voor "keywords", commentaar, strings etc etc. Het niveau van inspringen wordt net zolang vastgehouden totdat je dit zelf wijzigt. Het gedrag en uiterlijk van de Source Editor kun je instellen via Environment -> Editor options. Je ziet dan een dialoog met verschillende tabs waarop je verschillende instellingen kunt doen.
  • Code Explorer: Een handig scherm waarmee je snel naar bepaalde punten in je code kunt springen. Dit scherm wordt standaard aan de rechterkant van je desktop getoond. Dit scherm toont in een boomstructuur de code van de in de source editor actieve file. Als het geopend wordt toont het alleen de naam van de unit en takken voor de interface en implementatie secties van de file, maar als je klikt op
    +
    knop aan de linkerkant van een tak, zal deze uitklappen. Hierdoor worden meer details getoond totdat iedere individueele constante, variabele, procedure en functie decleratie worden getoond. Als je de file in de editor wijzigt moet je op refresh klikken om de code explorer de nieuwe stand van zaken te laten weergeven.
  • Units...: Opent een popup window met een lijst van alle bestanden in het project. Als je op een bestandsnaam klikt wordt deze geopend en getoond in de Source Editor. Je kunt ook meerdere bestande selecteren, dan worden alle gekozen bestanden in de source editor geopend. Via Project -> Project Inspector option kun je ook een lijst krijgen, maar dit zijn alleen source bestanden.
  • Forms...: Hiermee wordt een pop-up window getoond met alle forms in het project. Klik op een form en het wordt actief gemaakt, zodat je het kunt wijzigingen.
  • View Unit Dependencies: Laat een scherm zien met een boomstructuur die per unit de afhankelijkheden van die unit laat zien. The meeste bestanden die als afhankelijkheid worden getoond zullen zelf ook weer een
    +
    box hebben, waardoor je steeds dieper meer afhankelijkheden ziet, vaak in recursie.
  • Toggle form / unit view F12: Schakelt heen en weer tussen de source editor en het form dat bij de bewerkte unit hoort. Als de focus op de Source Editor ligt, kun je de source code aanpassen. Heeft het Form ontwerp focus, dan kun je daar wijzigingen in aanbrengen. De makkelijkste manier om te schakelik tussen Source Editor en Form is de F12 toets.
  • Messages: Laat het Messages scherm zien. In dit scherm worden de compiler berichten getoond.
  • Search Results: Een scherm dat de resultaten toont van het zoeken in bestanden.
  • Debug windows: Hiermee wordt een submenu getoond waarin je de verschillende debug-schermen kunt oproepen. Hieronder wordt de debugger beschreven.

Het Project menu

  • New Project: Maakt een nieuw project. Er verschijnt eerst een dialog scherm waarin de keuze voor het type project gemaakt moet worden.
  • New Project from file: Er wordt een open bestand dialoog getoond waarmee naar een bestand ge"browsed" kan worden waarvan een nieuw project gemaakt wordt.
  • Open Project Er wordt een open bestand dialoog getoond waarmee je een Lazarus Project Information (.lpi) file kunt aangeven, zodat er een bestaand project geopend kan worden.
  • Open Recent Project: Geeft een pop-up menu met de laatst geopende projecten.
  • Save Project: Vergelijkbaar met File -> Save all: alle bestanden van het huidige project worden opgeslagen. Als er nog geen filenaam bekend is van een file dan wordt hier omgevraagd.
  • Save Project As...: Vraagt om een naam voor het project. Bij een nieuw project wordt de default Project1.lpi aangeboden. Je kunt niet dezelfde naam gebruiken voor het project als voor een bestand / unit in dit project. (Zie ook below).
  • Publish Project: Maakt een kopie van alle tot het project behorende bestanden. Ideaal voor het versturen van de source van je project naar een collega. In een project directory staan een aantal bestanden die niet noodakelijk zijn. De .lpi file bijvoorbeeld bevat informatie over de sessie, zoals bookmarks, de plaats van de cursor etc. Tevens staan er een aantal .ppu, .o bestanden de executable in de directory. Zie ook Lazarus IDE Tools
  • Project Inspector: Opent een scherm met een boomstructuur waarin de bestanden van het huidige project getoond worden. Je kunt hier bestanden toevoegen, verwijderen en openen en bepaalde opties voor het project wijzigen.
  • Project Options...: Opent een dialoog scherm met een aantal tabs om bepaalde opties te zetten voor de Applicatie (Titel, Doel bestandsnaam), Forms (hier kun je aangeven welk form het "mainform" is en welke forms automatisch gemaakt moeten worden) and Info (waarin ondermeer aangegeven kan worden of de editor informatie, zoals cursorpositie, alleen voor de project files moet worden opgelsagen of voor alle geopende files).
  • Compiler options ...: Opent een dialoog scherm met een aantal tabs om de compiler te kunnen configureren. Tabs zijn ondermeer Paths, om zoekpaden naar units, include files en dergelijke aan te geven; Parsing voor het aangeven van een aantal "Parse" opties; Code om optimalisatie opties te kiezen; Linking met keuzes met betrekking tot debugging, statisch of dynamisch geladen libraries, en of deze opties doorgegeven moeten worden aan de linker; Messages definieert de meldingen die de compiler genereerd; Other hier kun je aangeven dat er een andere cfg-file gebruyikt moet worden, dan de standaard fpc.cfg; Inherited laat zien welke opties worden overgenomen van andere units; Compilation hier kunnen opdrachten opgegeven worden die voor of na de compilatie uitgevoerd moeten worden.
  • Add editor file to Project: Voegt het bestand dat in de editor actief is, aan het projet toe.
  • Remove from Project: Toont een lijst met bestanden die deel uitmaken van het project zodat je aan kunt geven welk bestand verwijderd kan worden.
  • View Source: Laat het "hoofd"bestand van het programma zien. Dit is meestal het project bestand (.lpr).
  • View ToDo List: Laat een lijst met "ToDo" dingen zien. de lijst wordt opgebouwd uit de commentaar regels die met //TODO beginnen. Je kunt zelf de items nummere door achter //TODO een volgnummer te zetten.

The Run sub-menu

  • Build: Causes Lazarus to build (ie compile) any files in the project that have been changes since the last build.
  • Build all: Builds all files in the project, whether or not there have been any changes.
  • Abort build: Stop the build process once it is running - either you have remembered that you did something silly and want to stop the build, or the system seems to be taking far too long and something is obviously wrong.
  • Run: This is the usual way to launch the compiler and, if compilation is successful, to start execution of the application. What actually happens is that Lazarus saves a copy of your files, then starts the compiler and linker, then begins execution of the final linked binary program.
  • Pause: Suspend execution of the currently running program. This may allow you to inspect any output that has been generated; execution may be resumed by selecting Run again.
  • Step into: Used in conjunction with the debugger, causes execution of the program one step at a time up to a bookmarked point in the source.
  • Step over: Causes stepwise execution up to the statement marked, then skips the marked statement, and continues execution at normal speed. Useful in trying to isolate a statement that introduces a logical error.
  • Run to cursor: Causes execution at normal speed (ie NOT one statement at a time) until the statement is reached where the cursor is located; then stops. Resume execution at normal speed by selecting Run.
  • Stop: Cease execution of the running program. Cannot be resumed by selecting Run; this will start the program again from the beginning (re-compiling if necessary).
  • Run Parameters: Opens a multi-page pop-up window which allows command-line options and parameters to be passed to the program to be executed; allows selection of display to run program (eg a remote X terminal may be used in Linux); some system Environment variables may be overridden.
One very important use of this sub-menu is to activate a terminal window in which conventional Pascal console input/output is displayed. If you are developing a console-mode Pascal program (ie one that doesn't use the Graphical User Interface with its forms, buttons and boxes) then you should check the box for "Use launching application". The first time you do this and try the Compile/Run sequence, you will probably get a rude message to say
"xterm: Can't execvp /usr/share/lazarus//tools/runwait.sh: Permission denied".  
If this happens, you need to change the permissions on the appropriate file (for example using chmod +x filename, or using the Windows utility for changing permissions); you might have to do this as root. After this, each time you launch you program, a console box will appear and all your text i/o (readln, writeln etc) will appear in it.
After your program has finished execution, a message "Press enter" appears on the screen. Thus any output your program generated will remain on the screen until you have had a chance to read it; after you press 'enter' the console window closes.
See the separate tutorial on Console Mode Pascal programming.
  • Reset debugger: Restores the debugger to its original state, so that breakpoints and values of variables etc are forgotten.
  • Build file: Compile (build) just the file that is currently open in the Editor.
  • Run file: Compile, link and execute just the currently open file.
  • Configure Build + Run File: Opens a multi-page tabbed window with options to allow for build of just this file when Build Project is selected, allows selection of the working directory, the use of various Macros, etc. Then Builds and Runs the file.

NOTE: I AM NOT REALLY CLEAR IN WHAT CIRCUMSTANCES YOU WOULD USE THESE LAST THREE SELECTIONS; IN PARTICULAR, WHAT HAPPENS TO OTHER FILES THAT ARE USED BY THE PROGRAM? User:Kirkpatc

The Components sub-menu

  • Open Package: Displays a list of installed packages, with an invitation to open one or more of them, or to select various general or compiler options.
  • Open Package File: Open one of the files in the selected package.
  • Open Recent Package: Open a package that was opened recently.
  • Add Active Unit to Package: Place the unit file (currently in the editor) into a package.
  • Package Graph: Displays a graph showing the relationships of the packages currently being used (if you aren't using any other packages, the Lazarus package and the FCL and LCL will be displayed).
  • Configure custom components: If you have created some components, allows you to configure them.

The Tools sub-menu

  • Configure custom tools: Allows the user to add various external tools (usually macros) to the toolkit
  • Quick syntax check: Perform a quick check of the syntax in your source file without actually compiling anything. Essential step in developing long or complicated programs, where you don't want to waste time compiling if the code is wrong.
  • Guess unclosed block: useful utility if you have a complex nested block structure and you have left out an 'end' somewhere
  • guess misplaced IFDEF/ENDIF: useful if there is a complex or nested macro structure and you think you have left out an ENDIF directive
  • Make resource string: I NEED SOME HELP IN DESCRIBING THE FUNCTION OF THIS SELECTION: I HAVE NEVER USED IT MYSELF AND DON'T REALLY KNOW WHAT IT DOES. User:Kirkpatc
  • Diff: Allows comparison between two files (or, usually, two versions of the same file) to find differences. Options to ignore white space at beginning or end of lines or differences in line termination: CR+LF versus LF). Useful for checking if there have been changes since last CVS update etc.
  • Check LFM file in editor: Allows inspection of the LFM file which contains the settings that describe the current form
  • Convert Delphi unit to Lazarus unit: Helps in porting Delphi applications to Lazarus; makes the necessary changes to the source file. See Lazarus For Delphi Users and Code Conversion Guide.
  • Convert DFM file to LFM: For porting from Delphi to Lazarus: converts the Form Description files from Delphi to Lazarus. See Lazarus For Delphi Users and Code Conversion Guide.
  • Build Lazarus: Launches a re-build of Lazarus from the most recently downloaded or updated CVS files. Hit the button and sit back to watch it happen! (track the process on your Messages window).
  • Configure "Build Lazarus": Allows the user to determine which parts of Lazarus should be re-built, and how. For example, you could select to have just the LCL re-built, or to have everything except the examples built; you can select which LCL interface to use (ie which set of widgets), and you can select the target operating system and specify a different target directory.

The Environment sub-menu

  • Environment options: Displays a multi-page window with tabs for
    • Files - allowing the user to specify path to default directory, compiler, source directory and temporary directory for compilation;
    • Desktop - options for Language, Auto save behaviour, saving desktop properties, hints for component palette and speed buttons;
    • Windows, to allow specification of size and behaviour of the various windows;
    • Form Editor - choose colours for editing forms;
    • Object Inspector - choose colour and height of items;
    • Backup - specify how to backup files when editing;
    • Naming - specify what extension to use in naming pascal files ('.pp' or '.pas'), whether to save files with names in lowercase, whether to perform auto-delete or auto-rename.
  • Editor options: Multi-page window, with tabs for
    • General - determines behaviour like auto-indent, bracket highlighting, drag-drop editing, scrolling, syntax highlighting, showing hints, size of block indent and tabs, limit of Undo;
    • Display - options for showing line numbers, presence of gutters, size and type of font for editor, and contains a preview panel showing the colours of the various syntax features such as comments, directives, punctuation, errors and breakpoints;
    • Key Mappings - options to select Lazarus or Turbo Pascal scheme;
    • Color - allows choice of colour scheme for text features, for a number of language types such as Object Pascal, C++, Perl, HTML, XML and shell scripts. It shows preview panel again (for whichever language is selected);
    • Code Tools - allows selection of features like Identifier Completion, tooltips, specification of template file names, specific templates for code completion.
  • Debugger Options: Multi-page window with tabs for
    • General - choose debugger: none, GNU debugger (gdb) or gdb through SSH, specify search paths for debuggers,and specific options for chosen debugger;
    • Event log - specify whether to clear log on run, and which messages to display;
    • Language Exceptions - select which exceptions can be ignored;
    • OS Exceptions - allows user to add certain signals which apply to current operating system.
  • Code Tool Options: Multi-page window, tabs for
    • General - Allows entry of additional source search paths, specify Jumping Method;
    • Code Creation - determines whether created code is added before or after certain features;
    • Words - determines whether Pascal keywords are to be entered in upper or lower case, or as Capitalised Words;
    • Line Splitting - establish rules about where lines are allowed to be split (before or after punctuation, after keywords etc);
    • Space - decide whether a space is to be added automatically before or after certain syntactic features such as keywords or punctuation marks.
  • Code Tools Defines Editor: I NEED SOME HELP IN DESCRIBING THIS, AS I HAVEN'T A CLUE WHAT THIS ITEM IS FOR! User:Kirkpatc


  • Re-scan FPC Source directory Looks through the directory again. Lazarus uses the fpc sources to generate correct event handlers and while looking for declarations. If somebody changes the directory in the environment options, then this directory is rescanned, to make sure lazarus uses the version stored in that location. But if this directory has changed without lazarus noticing, then you may get some errors when designing forms or doing "Find declaration". If you get such an error, you can do two things:
    1. Check the fpc source directory setting in the environment option.
    2. Re-scan FPC source directory.

The Windows sub-menu

Contains a list of the currently opened files and the available windows such as Source Editor, Object Inspector and Project Inspector. Clicking on the name of one of the windows brings it to the foreground and gives it focus.

The Help sub-menu

At present this has three selections:

  • Online Help which at present opens a browser window that contains a picture of the running cheetah and a few links to the Lazarus, FreePascal and WiKi websites
  • Configure Help which opens a pop-up menu with options to select viewers and databases from which to read Help information. This option allows the user to specify either the on-line documents section of the Lazarus-CCR website, some other website containing the documents, or a local store for the documentation (this would eventually become the default, when the Help system is fully developed).

At present by default, if you place your Editor cursor over any keyword from the FreePascal Components Library FCL or the RunTime Library RTL (but not the Lazarus Components Library LCL) and then press <<F1>> you will be taken to the appropriate definition on the website. THIS SECTION STILL REPRESENTS WORK IN PROGRESS

  • About Lazarus Displays a pop-up box with some information about Lazarus.

Eventually there will be a full on-line Help service, with information about Pascal syntax, the use of the IDE, how to use, modify or create Components, and hints on how to perform certain tasks. This part of the Documentation section (the thing you are currently reading) represents the beginning of the process. We need contributions from anyone who feels able to provide them: the WiKi is very easy to edit.

The Button bar

A small toolbar area on the left of the main editor window, just below the Main Menu and to the left of the Component Palette, contains a set of buttons which replicate frequently-used Main Menu selections:

New unit, Open (with a down-arrow to display a drop-down list of recently used files), Save, Save all, New Form, Toggle Form/Unit (ie show either form or source code of Unit), View Units, View Forms, Run (ie compile and Run), Pause, Step Into, Step over (the last two are Debugger functions).

The Component Palette

A Tabbed toolbar which displays a large number of icons representing commonly used components for building Forms.

Each tab causes the display of a different set of icons, representing a functional group of components. The left-most icon in each tabbed group is an obliquely leftward-facing arrow, called the Selection Tool.

If you allow the mouse cursor to hover over any of the icons on the Component Palette, without clicking on the icon, the title of that component will pop-up. Note that each title begins with a 'T' - this signifies 'Type' or more accurately 'Class' of the component. When you select a component for inclusion in a form, the Class is added to the type section of the interface part of the Unit (usually as part of the overall TForm1), and an instance of that class is added to the var section (usually as the variable Form1). Any Methods that you design to be used by the Form or its Components (ie Procedures or Functions) will be placed in the implementation part of the Unit

In the following list of the Components, you will find links to files that contain descriptions of the Units in which they are found. If you want to find out about the properties of a particular component, it is often worth looking at the Inheritance of that component and then inspecting the properties of the base type from which it is derived. For example, to understand TMaskEdit it is also useful to examine TCustomMaskEdit.

TABS (the names are largely self-explanatory):

  • Standard: Frequently used components: TMainMenu, TPopupMenu, TButton, TLabel, TEdit, TMemo, TToggleBox, TCheckBox, TRadioButton, TListBox, TComboBox, TScrollBar, TGroupBox, TStaticText, TRadioGroup, TCheckGroup, TPanel, TActionList
  • Additional: More, often-used components: TBitBtn, TSpeedButton, TImage, TShape, TBevel, TPaintBox, TNotebook, TLabeledEdit, TSplitter, TMaskEdit, TCheckListBox, TScrollBox, TApplicationProperties, TStringGrid, TDrawGrid, TPairSplitter
  • Common Controls: TTrackBar, TProgressBar, TTreeView, TListView, TStatusBar, TToolBar, TUpDown, TPageControl, TImageList
  • Dialogs: TOpenDialog, TSaveDialog, TSelectDirectoryDialog, TColorDialog, TFontDialog, TOpenPictureDialog, TSavePictureDialog, TCalendarDialog, TCalculatorDialog

Several useful Dialog procedures or functions don't appear on the Palette, but are easily used as direct calls from your source program.

For several good examples of the use of Components see the $LazarusPath/lazarus/examples subdirectory of your source installation. Many of the programs show how to use dialogs and other components directly without using the IDE and component palette or having a separate form definition file: all the components are fully and explicitly defined in the main Pascal program. Other example programs make full use of the IDE.

Some examples don't work straight away: you may need to play about with paths and permissions of files or directories. If you want to compile any of the examples, make sure that you have read/write/execute permissions for the files and directories, or copy the files to a directory where you do have the appropriate permissions.

Try running the 'testall' program to see a menu of the available components together with small example test forms for most of them; then inspect the code to find out how they work!

  • Misc: TColorButton, TSpinEdit, TArrow, TCalendar, TEditButton, TFileNameEdit, TDirectoryEdit, TDateEdit, TCalcEdit, TFileListBox
  • Data Controls: Data-aware components, which largely replicate the Standard and Additional groups but are applicable to Databases: TDBNavigation, TDBText, TDBEdit, TDBMemo, TDBImage, TDBListBox,TDBComboBox, TDBCheckBox, TDBRadioGroup, TDBCalendar, TDBGroupBox, TdbGrid
  • Data Access: TDatasource
  • System: TTimer, TIdleTimer, TProcess
  • SynEdit: A group of components to help interfacing with other languages and software tools. SynEdit is an advanced multi-line edit control, for Borland Delphi, Kylix and C++Builder. It supports Syntax Highlighting and code completion, and includes exporters for html, tex and rtf. It is a full-VCL/CLX control, meaning it is not a wrapper for Microsoft Windows controls, and no run-time library is required; this make SynEdit a crossplatform component. Compatibility with FreePascal is also planned, and SynEdit is the edit component in Lazarus IDE. see synedit at sourceforge. TSynEdit, TSynAutoComplete, TSynExporterHTML, TSynMacroRecorder, TSynMemo, TSynPasSyn, TSynCppSyn, TSynJavaSyn, TSynPerlSyn, TSynHTMLSyn, TSynXMLSyn, TSynLFMSyn, TSynUNIXShellScriptSyn, TSynCssSyn, TSynPHPSyn, TSynTeXSyn, TSynSQLSyn, TSynMultiSyn

To use the Palette, there must be an open form on view in the editor (if there isn't one, select File -> New Form). Click on the icon in the appropriate tab of the Palette for the component you want to use, then click on the Form, near where you want the component to appear. When the desired component appears, you can select it by clicking with the mouse, then move it to the exact place on the Form where you want it and adjust its size. Adjustments can be made to the appearance either by altering the picture itself on the Form using the mouse, or by changing the relevant Property in the Object Editor for that component.

If you install additional components, either those you have written yourself, or some coming as a package from some other source, then extra tabs with the relevant icons will appear in your Component Palette. These new components can be selected and used on your forms in the same way as those supplied by default.

The Debugger

Still to be written.

The Lazarus files

   (Thanks to Kevin Whitefoot.)
   (Additions by Giuseppe Ridinò, User:Kirkpatc and Tom Lisjac)

When you save you will actually be saving two files:

  xxx.pas and yyy.lpr 

(You save more than that but those are the ones you get to name). The project file (lpr) and the unit file (pas) must not have the same name because Lazarus will helpfully rename the unit (inside the source code) to the same as the unit file name and the program to the name of the project file (it needs to do this or the compiler will probably not be able to find the unit later when referred to in the project file). Of course to be consistent it changes all the occurrences of unit1 to xxx.

So if you are saving a project called again, trying to save again.pas and again.lpr fails because unit names and program names are in the same name space resulting in a duplicate name error.

So here is what I ended up with:

e:/lazarus/kj/lazhello:

total 4740  free 76500
-rwxrwxrwx   1 kjwh     root  4618697 Mar 24 11:19 again.exe
-rw-rw-rw-   1 kjwh     root     3002 Mar 24 11:21 again.lpi
-rw-rw-rw-   1 kjwh     root      190 Mar 24 11:18 again.lpr
-rw-rw-rw-   1 kjwh     root      506 Mar 24 11:08 againu.lfm
-rw-rw-rw-   1 kjwh     root      679 Mar 24 11:08 againu.lrs
-rw-rw-rw-   1 kjwh     root      677 Mar 24 11:08 againu.pas
-rw-rw-rw-   1 kjwh     root     2124 Mar 24 11:08 againu.ppu
-rwxrwxrwx   1 kjwh     root      335 Mar 24 11:07 ppas.bat

Note that there are many more files than the two that I thought I was saving.

Here is a brief note about each file:

again.exe: The main program binary executable. Win32 adds an "exe" extension. Linux has none. This file will be huge on Linux due to the inclusion of debugging symbols. Run the "strip" utility to remove them and substantially shrink the executable size.

again.lpi: This is the main file of a Lazarus project (Lazarus Project Information); the equivalent Delphi main file of an application will be the .dpr file. It is stored in an XML format.

again.lpr: The main program source file. Despite its lazarus specific extension it is in fact a perfectly normal Pascal source file. It has a uses clause that lets the compiler find all the units it needs. Note that the program statement does not have to name the program the same as the file name.

againu.lfm: This is where Lazarus stores the layout of the form unit. Lazarus uses this to generate a resource file that is included in the initialisation section of the againu.pas unit. Delphi dfm files can be converted to lfm format in the Lazarus IDE using the Tools->Convert DFM file to LFM utility.

again.lrs: This is the generated resource file. Note that it is not a Windows resource file.

againu.pas: The unit that contains the code for the form.

again.ppu: This is the compiled unit.

ppas.bat: This is a simple script that links the program to produce the executable. If compilation is successfull, it is deleted by the compiler.

Medewerkers en wijzigingen

Dit is een vertaling van Lazarus Tutorial

Aanvang vertaling op 25 maart 2005 door Matthijs Willemstein