Lazarus Tutorial/it

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) suomi (fi) français (fr) magyar (hu) italiano (it) 日本語 (ja) македонски (mk) Nederlands (nl) português (pt) русский (ru) slovenčina (sk) shqip (sq) 中文(中国大陆)‎ (zh_CN) 中文(台灣)‎ (zh_TW)

This is the start of a Lazarus Tutorial. Please feel free to add your experiences to it.

Overview

Lazarus è un strumento di sviluppo gratuito per compilatori Free Pascal, anche esso gratis e open source. L' IDE Lazarus (screenshot) è uno stabile e ricco ambiente di sviluppo per la creazione di applicazioni grafiche e da console. Lazarus attualmente funziona su Linux, Mac OS X e Windows e fornisce un editor di codice customizzabile ed un ambiente visuale con un package manager, un debugger ed una completa integrata GUI con un compilatore pascal free.

Si inizia - Il tuo primo programma in Lazarus!

(Un ringraziamento a User:Kirkpatc)

Get, install (Installing Lazarus) and launch Lazarus which will also make available the FreePascal Compiler.

Several windows will appear on the desktop: the main menu at the top, the Object Inspector on the left, the Lazarus Source Editor occupying most of the desktop, and a ready-made Form1 window overlying the Source Editor.

On the top Menu window, underneath the menu line, is a row of tabs. If the 'Standard' tab is not already selected, select it by clicking with the mouse. Then find the Button icon (a rectangle with 'OK' on it) and click on that with the mouse. Then click on the Form1 window, somewhere to the left of the middle. A shadowed rectangle labelled 'Button1' will appear. Click again on the Button icon in the Standard tab, and click on the Form1 somewhere to the right of centre: a rectangle labelled 'Button2' will appear.

Now click on Button1 to select it. The Object Inspector will display the properties of the object Button1. Near the top is a property named 'Caption', with the displayed value 'Button1'. Click on that box, and change 'Button1' to 'Press'. If you hit ENTER or click in another box, you will see the label of the first button on Form1 change to 'Press'. Now click on the Events tab on the Object Inspector, to see the various events that can be associated with the button. These include OnClick, OnEnter, OnExit etc. Select the box to the right of OnClick: a smaller box with three dots (... ellipsis) appears. When you click on this, you are taken automatically into the Source Editor and your cursor will be placed in a piece of code starting:

 procedure TForm1.Button1Click(Sender: TObject);
 begin
   {now type:}    Button1.caption := 'Press again';
   {the editor has already completed the procedure with}
 end;

Press F12 to select the Form1 window instead of the Source Editor.

Now edit the properties of Button2: click on Button2 to display its properties in the Object Inspector. Change its Caption property to 'Exit' instead of 'Button2'. Now select the Events tab, and click on the box for OnClick. Click on the ... ellipsis, and you will be taken into the Source Editor, in the middle of another procedure:

 procedure TForm1.Button2Click(Sender: TObject);
 begin
 {now type:}   Close;
 {the editor has already completed the procedure with} 
 end;

Now Press F12 to see the Form1 window again. You are now ready to try to compile. The simplest way to do this is to select 'Run' from the main menu at the top, and then the 'Run' option on the sub-menu. Alternatively you could simply type F9. This will first compile and then (if all is well) link and execute your program.

Several text windows will appear and all sorts of compiler messages will be typed, but eventually your Form1 window will re-appear, but without the grid of dots; this is the actual main window of your application, and it is waiting for you to push buttons or otherwise interact with it.

Try clicking on the button labelled 'Press'. You will notice that it changes to 'Press again'. If you press it again, it will still say 'Press again'!!

Now click on the button marked 'Exit'. The window will close and the program will exit. The original Form1 window with the grid of dots will reappear, ready to accept more editing activity.

You should save your work now