Delphi Source Code
Search engine
HOME Components Tutorials Add Trick Links Contacts
ActiveX Components Database Files Forms Graphic Internet/Lan Math Miscellaneous Multimedia Printing Strings System Information Windows

Delphi Tutorial for "Introduction to Delphi"
Page: [1] [2] [3] [4] [5] [6]

Basic Delphi

Introduction

For this tutorial I assume that you are familiar with Pascal. If you are not, read one of the many Turbo Pascal tutorials first (search for "pascal tutorial" in Yahoo). It also helps to know the concepts of object oriented programing (OOP), but I'll briefly explain this.

Please excuse all the typos and other faults. English is not my native language.

Delphi

Delphi is a so called RAD-Tool (RAD stands for Rapid Application Development). It allows you to visually design (by using drag-and-drop) dialog and even whole applications. In the toolbar of the main window you can find a lot of predifined conponents to use on your projects. Simple double-click on the icons to paste them into the active form. On the left hand side of your screen is the object inspector. You can set properties for your components. There is no need to write source code for this! A good way to learn Delphi is to play around with the components.

A first example

  1. Choose File - New Application
    This will create a empty form to which you can add all the components you want.
  2. You can now add components from the component palette by double-clicking on them. To change their size select them, click on one of the corners and move the mouse.
    As a first step add a button (sixth from the left in the "standard" palette). It'll be in the middle of the form. Move it any place you want. The button will have "button1" written on it which is not very usefull for your program. To change the text on the button (it is called caption), go to the object inspector and change the "Caption" field.
  3. Now the user could click on the button in your program, but nothing would happen. To assign any actions to the button double-click on it. Delphi brings up the source code window. The cursor is already in the correct position.
  4. You can put any pascal code in the procedure. For this example simply type "close;". This closes the form and terminates the application.
  5. Your project is now ready to be compiled. Choose File - Save As to save it. I recommend you use different directories for all your projects because they tend to have many files (at least 5).
  6. To compile and execute the project click on the "play" button in the toolbar.
  7. You will see a window that can be resized and moved around the normal "windows" way. You can close it by either clicking your button, clicking on the "close"-button in the top right corner, or selecting close from the window menu (top left corner).

The IDE

When you start Delphi for the first time, you see a couple of windows. You will also notice that there is no parent window which contains all other (child) windows. Instead there is a main window (on top of the screen) that has a menu bar and the icons. It also offers a component palette (which will be discussed later). On the left side of the screen you can see the object inspector. It allows you to change the properties of the current component.

The components

You can find the components you will need most on the first three tabs in the component palette. I am not going to discuss all of them here, refer to the help file if you have specific questions. Here is an overview over the most important components:

  • MainMenu
    Lets you add a standard menu bar to your form. To change the contents double-click on the icon on the form.
  • Label
    Puts text on your form. The character in the caption with a "&" in front of it will be underlined. You can link another component such as TEdit to it by using the FocusControl Property. When the user pressen Alt+CHARACTER that component will be selected. Modify the appearence of the text with the "font" property.
  • Edit
    Allows the user to input text. He can also use cut & paste to the Windows clipboard.
  • Memo
    Multi-line Edit.
  • Button
    Powerful properties are "default" and "cancel" (make button default- or cancel-button).
  • Checkbox and Radiobutton
    Allow the user to switch them on and off. From a group of radiobuttons only one can be selected.
  • Listbox and Combobox
    Display lists. User can select an entry by clicking on it. You can allow multiple selections, make them sorted, etc.
  • Image
    Probably easiest way to add a bitmap to your form. Use the "picture" property.
  • Tab- and Pagecontrol
    Let you put more components on a form than would normally fit by providing several layers. The user can switch between the layers by using the tabs on top of the control. You can use the page-editor to add pages at design time. This control is often used for option dialogs.

To add a component to your form simply double-click on it. You can move it arround with the mouse and customize its properties in the object inspector. To start your program just press the "play" button in the main window.



Page: [1] [2] [3] [4] [5] [6]
Delphi Tricks
Delphi Tricks
For any problems or recommendations about Delphi Tricks site, please

feel free to contact us on that e-mail: support@delphitricks.com.
If you want to advertise on the site use that e-mail: advertise@delphitricks.com.

You can freely use or modify these Delphi source codes for non-commercial use. We are not responsible of any damages that can be caused by the utilisation of that source codes.

Copyright © 2006 AVSoftware Company. All rights reserved.