Login Register






Learn DELPHI with Legolas | Part 1 filter_list
Author
Message
Learn DELPHI with Legolas | Part 1 #1
The Delphi Programming Language


Hello [username] !

I decided to make some complete threads about Delphi (Object Pascal) because there is not something similar here and actually nowhere else, with which i will show you. I have the opinion that Delphi, can support big projects, like Java and C++.
And i have used it, in many of my projects, so it will be nice to provide you my knowledges. Actually, i love this language. The original Object Pascal doesn't really exist in a distinct form any more. Borland developed Delphi 1 and incorporated much of the Apple Object Pascal language. So the language for the Delphi product was originally named Object Pascal. Apple stopped developing Object Pascal and it was never standardised as had been originally intended.
For the release of Delphi 6, Borland chose to rename their language as Delphi.


[Image: ug7zdac.png]


So, Pascal is a family of languages, with Object Pascal as sub-family, and Delphi a sub-family of Object Pascal.

________________________________________________________________________________________________________________



What is Delphi?

Delphi is a Windows application that based on object-oriented programming and the programming language Pascal. Anyone who has an experience in other object-oriented applications, such as Visual Basic, will find many similarities in the development of applications. Unlike with the older, "traditional" systems of application development, Delphi is driven by events (event driven), which means that it does not perform successive the commands of a program, from beginning to end, but awaits the appearance of events and executes the program code (procedure or function) associated with these events. An event is an action that comes from the user or by the system and examples of events are pressing (clicking) of the mouse, on a command button, the moving of the mouse over an object, the selection of an item in a menu etc.

History of Delphi

The Delphi programming language was developed by Borland and is the descendant of Turbo Pascal. Delphi was released in February 1995. Delphi is a native code compiler that runs under Window v3.1 or Windows '95.
Delphi is essentially object Pascal with similar programming tools found in Microsoft Visual Basic 3.0. Delphi is the first programming language to shatter the barrier between high-level, easy-to-use rapid application development environments and
low-level bits-and-bytes power tools.

On February 8, 2006 Borland announced that it was looking for a buyer for its IDE and database line of products, including Delphi, to concentrate on its ALM line.
On November 14, 2006 Borland transferred the development tools group to an independent subsidiary company named CodeGear, instead of selling it. Borland sold CodeGear to Embarcadero Technologies in 2008.
Embarcadero retained the CodeGear division created by Borland to identify its tool and database offerings, but identified its own database tools under the DatabaseGear name.
On September 12, 2013 Embarcadero released RAD Studio XE5, which includes Delphi XE5 and C++Builder. It added support for :
  • Android
  • Ice Cream Sandwich
  • Jelly Bean
  • iOS 7


Advantages of Delphi
  • A structured programming language and syntax are clear, so easy to read, studied and understood .
  • Clear Syntax.
  • You can develop any type of applications.( Web applications, mulitmedia, mobile applications)
  • Speed || Delphi isn't an interpreted language – it compiles to machine code, making it exceptionally fast.
  • No runtime. Languages such as C# and VB.NET require the .NET runtime
  • The language is suitable for Rapid Application Development (RAD) and Delphi includes an integrated IDE.
  • Startup time. || Related to the above, well-designed Delphi applications start quickly because they don't have to wait for any runtime to load (assuming it's not already loaded).
  • Ability to create easily powerful, scalable and secure database applications. ( Delphi has a powerful database development capabilities.)
  • Provides native access to the high-performance Advantage Database Server.
  • Delphi can access many types of databases.( local databases like: Paradox ,DBase, network SQL server databases, like SQL Server, Oracle and InterBase, and any data source accessible though ODBC)
  • Users can build single-source applications for both Windows and MAC (iOS).
  • Ability to create iOS mobile applications for the iPhone, iPod Touch and iPad.
  • All the common parts of the graphical user interface, like forms, buttons and lists objects, are included in Delphi as components / controls.
  • Low level features: ability to use third party DLLs, write assembler code blocks, or use Windows hooks.
  • Support for the entire Windows API.
  • With Delphi, you can write Windows programs more quickly and more easily than was possible ever before.
  • Delphi allows the developer to design the entire interface visually, and quickly implement an event driven code with the click of the mouse.
  • Delphi is not created by Microsoft.( Someone who had experience with Microsoft development tools, can understand why i am telling this as advantage :Thumbs-Up: Smile

Disadvantages of Delphi

Delphi can almost be said to be perfect. If you work with Delphi, it's hard for you to change to other langauges, because it's so powerful. You will love it.:HeartEyes:
The biggest disadvantage of Delphi is that it's not so popular such as C, Java, Objective-C, so there are not many Delphi jobs. But on the other hand, there are also a lot more Java and C++ programmers than Delphi programmers.
So it's harder to stand out as a Java or C++ programmer. Having a specialism that not many people have, such as for example Delphi, may help you get a higher salary, though you'll have to search harder to find Delphi jobs.
This can be an advantage as well as a disadvantage. Delphi has been rather marginalized for some time now, and doesn't seem to be in the process of making a huge comeback.

It's definitely worth learning Delphi. A lot of softwares still being written in it, stuff which people use and rely on.

I would not recommend Delphi as a first language for someone who tries to learn programming on his own.



Compilers of Delphi
  • Embarcadero Delphi XE6 || Latest Version || Recommended.
  • Embarcadero Delphi XE5.
  • Borland
  • Oxygene || developed by RemObjects Software.
  • Free Pascal (FPC) || open-source Pascal compiler.
  • Project JEDI || Open Source project.
  • Lazarus.


Identifiers of Delphi
  • Reserved words cannot be used as identifiers.
  • Identifiers denote constants, variables, fields, types, properties, procedures, functions, programs, units, libraries,
    and packages.
Delphi is case-insensitive language, so an identifier like 'HackCommunity' could be written in any of these ways:
  • HackCommunity
  • hackCommunity
  • HACKCOMMUNITY
  • hackcommunity
Spoiler:

If an identifier has been declared in more than one place, it is necessary to qualify the identifier. The syntax for a qualified identifier is:
identifier1.identifier2

Qualifiers can be iterated.. For example:
Form1.Button1.Click

calls the Click method in Button1 of Form1.




Comments in Delphi
  1. {you must not forget to close the comments, with the use of hooks }
  2. (* ..............................*)
  3. // These comments are only until the end of the current line.


Delphi reserved words

[table]
[row]
[cell] begin [/cell]
[cell] function [/cell]
[cell] string[/cell]
[cell]case [/cell]
[cell] except [/cell]
[cell] type [/cell]
[cell] and [/cell]
[cell]object [/cell]
[cell] finally [/cell]
[/row]
[row]
[cell] if [/cell]
[cell] const [/cell]
[cell] on [/cell]
[cell] or [/cell]
[cell] xor [/cell]
[cell] goto[/cell]
[cell] library [/cell]
[cell]div [/cell]
[cell]inline [/cell]
[/row]
[row]
[cell] constructor [/cell]
[cell] destructor [/cell]
[cell] procedure[/cell]
[cell] program [/cell]
[cell] uses [/cell]
[cell] do [/cell]
[cell] try[/cell]
[cell]asm [/cell]
[cell] packed [/cell]
[/row]
[row]
[cell] property [/cell]
[cell] initialization [/cell]
[cell] downto [/cell]
[cell] interface[/cell]
[cell] inherited [/cell]
[cell] class [/cell]
[cell] array [/cell]
[cell]shr [/cell]
[cell] as [/cell]
[/row]
[row]
[cell] raise [/cell]
[cell] while [/cell]
[cell] record [/cell]
[cell] var [/cell]
[cell] label [/cell]
[cell] in [/cell]
[cell] implementation [/cell]
[cell] nil[/cell]
[cell] end [/cell]

[/row]
[row]
[cell] with[/cell]
[cell] else [/cell]
[cell] is [/cell]
[cell] repeat [/cell]
[cell] until [/cell]
[cell] to [/cell]
[cell] unit [/cell]
[cell]shl [/cell]
[cell]------[/cell]
[/row]
[row]
[cell] exports[/cell]
[cell] set [/cell]
[cell] for[/cell]
[cell] not [/cell]
[cell] then [/cell]
[cell] of [/cell]
[cell] file [/cell]
[cell]mod [/cell]
[cell]------[/cell]
[/row]
[/table]

  • Reserved words can’t be redefined.
  • Reserved words appear in lowercase boldface throughout this manual. Object Pascal is not case sensitive, however, so you can use either uppercase or lowercase letters in your programs.


Delphi directives

[table]
[row]
[cell] absolute[/cell]
[cell] export[/cell]
[cell]abstract [/cell]
[cell] interrupt[/cell]
[cell] virtual[/cell]
[cell] resident[/cell]
[/row]
[row]
[cell] name[/cell]
[cell] published[/cell]
[cell]message[/cell]
[cell] index[/cell]
[cell] forward[/cell]
[cell]at [/cell]
[/row]
[row]
[cell]public [/cell]
[cell]external [/cell]
[cell]write [/cell]
[cell]override [/cell]
[cell] stored[/cell]
[cell]------- [/cell]
[/row]
[row]
[cell] near[/cell]
[cell]read [/cell]
[cell]protected [/cell]
[cell]nodefault [/cell]
[cell] cdecl[/cell]
[cell]------- [/cell]
[/row]
[row]
[cell]assembler [/cell]
[cell]far [/cell]
[cell]dynamic [/cell]
[cell]default [/cell]
[cell] private[/cell]
[cell]------- [/cell]
[/row]
[/table]

  • Directives are used only in contexts where user-defined identifiers can’t occur. Unlike reserved words, you can redefine standard directives, but we advise that you don’t.
  • private, protected, public, and published act as reserved words within object type declarations, but are otherwise treated as directives.


Datatypes

[Image: TFGpoVZ.png]
  • The Data types of Delphi are the same with the data types of Pascal.


Intro to Subroutines

Subroutines are an important part of any programming language. In Delphi, there are generally two types of subroutines: a function and a procedure.
The usual difference between a function and a procedure is that a function can return a value, and a procedure generally will not do so.

Code:
procedure SayHellotoHC(const sEveryone:string) ; begin ShowMessage('Hello ' + sEveryone) ; end;

Code:
function YearsOld(const BirthYear:integer): integer; var Year, Month, Day : Word; begin DecodeDate(Date, Year, Month, Day) ; Result := Year - BirthYear; end;

We will talk more about Subroutines in other parts.


Creating simple applications in Delphi - Hello World

Code:
procedure TForm1.Button1Click(Sender: TObject); begin ShowMessage('Hello Hackcommunity'); Close; end;


Console Application
:

Code:
program HelloHC; // In this line we declare, a program called HelloHC {$APPTYPE CONSOLE} (* The directive {$APPTYPE CONSOLE} is telling to Compiler that is a console application and being run from the command line ! *) var MyMessage : string; // We declare a Variable which is called MyMessage and this variable holds a string. begin MyMessage := 'Hello Hackcommunity!'; (* In this line, the program assigns the string "Hello Hackcommunity" TO the variable MyMessage *) Writeln(MyMessage); (* The Writeln procedure is a standard output. In this line, the program sends the contents of MyMessage to the Writeln procedure. *) end.


We saw before how the ShowMessage procedure displays messages in a dialog box.
There is the function InputBox( ), by which we can get information from the user. This function displays a dialog box that contains a title, a message, a text box and, if we desire, and a default value in the text box.
The return value of the function is what we will write in the text box.

The following program shows the use of InputBox( ) :

Code:
procedure TForm1.Button1Click(Sender: TObject); var Response : String; begin Response := InputBox('Hi', 'What's your name;', 'Legolas'); ShowMessage(‘Hi‘+Response); Close; { The message Hi will display in the title bar of the dialog box, the message What's your name; will display inside the dialog box and Legolas will be the default value for the variable Response, if we do not write something in the text box. Whatever we write in the text box will be considered as the return value of the function and will be inserted in the variable Response. } end;

Relax, i just showed you something to "take a taste" and get in the mood of Delphi.:Smile:. Let's take them again from beginning.:Thumbs-Up:


Constants

1.
Code:
const int j = 100; const float ADNumb = 3.14; const char * HackCommunity = “Skids go away!”;

2.
Code:
Const j = 100; ADNumb = 3.14; ErrorString = “Skids go away!”;

1st and 2nd code, is the same thing. You decide how you will write it.

!!!<> The Delphi compiler automatically allocates proper space for the constant based on its value, or, in the case of scalar constants such as Integer, the compiler keeps track of the values as it works, and space never is allocated.
So, Delphi doesn’t require you to declare the constant’s type along with the value in the declaration.

!!!<> Delphi, gives you the ability to specify a constant’s type in the declaration.This provides you with full control over how the compiler treats your constants:

Code:
Const j : Integer = 100; ADNumb : Double = 3.14; HackCommunity: string = “Skids go away!”;

Error:

Code:
const LeftSide : Integer = 10; begin LeftSide := 14; end.

This code produces a compile error on the assignment to the LeftSide variable in the begin...end block. To fix it, change the const declaration to a var declaration.


Statements and Variables

An assignment statement has the form:

Code:
variable := expression

Code:
//An assignment statement I := 10; //assigns the value 10 to the variable I .

Code:
J := J + 1;

Example of ther assignment statements:

Code:
Z := X + Y; Sum := Sum - 1; String[I] := 'A'; F := Sqr(Z) - I * K; Array[I + 2] := P^; Condition := True; Result := [I, Succ(C)]; Shortint(MyChar) := 118;

Compound Statements:

Code:
begin Z := X; X := Y; X := Y; end;


Declaring Variables:

Code:
var I: Integer; //declares the variable I of type Integer.

Code:
var X, Y: Real; //declares two variables X and Y of type Real.

Consecutive variable declarations:

Code:
var Value : Integer; NewAdress : string; Okay : boolean; IwantMoney : Currency; Something : variant; A, B, C : char; Ptr : Pointer; F, L, K : Real; M, Z, Z : Double; Str : string; Doub : Double;

Assigning values to variables:

Code:
Str = 'Hello world'; // String type Doub = 3.141579; //Double type IwantMoney := 687,49; //Curreny type Okay := True; //boolean type NewAdress := 'Mordor'; //string type

Warning:

Code:
IwantMoney := 'one million';

This is not allowed and we will get an error message. It's not allwed to assign string value to currency type variable.


As we saw before at Constants, a feature of Delphi is that it enables us to initialize global variables inside a var block.

Examples
:

Code:
Var Value: integer = 5; Str: string = 'Hello world'; NewAdress: string = 'Mordor';


A Comparison between C and Delphi:

Program in C:

Code:
void main(void) { int x = 6; x++; int y = 3; float f; y--; char Legolas; f = x + y/3 //...... }// End of Main

Program in Delphi:

Code:
Procedure Foo; var x, y: Integer; f: Double; Legolas: Char; begin x := 1; inc(x); { Don't worry about this. It's a function that increases the number by 1 point forward. I will talk more about Functions on other Parts. } y := 2; //.... end;

So what did you understand form this comparison ?

Click to see the answer :
Spoiler:
Delphi requires from user to declare all variables up front in their own section before he begins a procedure, function, or program.
Generally, in Delphi, you code must be a bit more structured.




At this point, i will stop the Part 1 of Delphi.

________________________________________________________________________________________________________________



In Part 2 and Part 3, i will talk about :
  • Operations
  • Overloading
  • Strings
  • Types
  • Functions
  • if - else // Decisions
  • Loops
  • Forms
  • Arrays
  • Records
  • Pointers
  • Data Structures
  • Delphi Databases // Database Development
  • Smart Techniques

And in Part 4 i will talk about Mobile Application Development with Delphi (iOS and Android).



So, we don't stop here. Stay tuned. More interesting threads are coming soon.
And don't forget, everything started from Pascal.:Thumbs-Up:


Thank you,
Legolas.
(This post was last modified: 08-29-2014, 04:53 PM by Pk2Global.)

Reply

RE: Learn DELPHI with Legolas | Part 1 #2
I will check tomorrow if it needs something. Let me know if i used any word which is not suitable or wrong.(English is not my main language).
I am tired right now, and i will take a small break. If you like it or if you don't please leave a message.
If you have any question, feel free to ask.

The other Parts will be more intersting. :Thumbs-Up:
[Image: T4OUWZ1.png]


Reply

RE: Learn DELPHI with Legolas | Part 1 #3
Added tutorial tag.
[Image: OilyCostlyEwe.gif]

Reply

RE: Learn DELPHI with Legolas | Part 1 #4
It's a shame that this isn't getting more attention than what it is because it's clear that you put a decent amount of effort into writing this. Though, this doesn't really surprise me because people generally don't discuss things that seem too complex for them, or something that they have next to no knowledge of. @Legolas, you asked me why people weren't giving this thread much attention, and I'll be straight up honest with you: they have no reason to learn it, and all of this can generally be a lot to take in. At least with something such as Java or C, you've heard of it before time and time again - you know that it CAN and WILL help you if you set your mind to it.

I'm personally not much of a programmer, so I wont actually be learning DELPHI. Though, it's good that you added this to HC because now people can search 'DELPHI' as a tag and actually come up with something; something is better than nothing. *cough* It'll help people like @1234hotmaster and @1llusion when they're looking for something like this. Link-related: www.hackcommunity.com/Thread-Delphi

EDIT: I just noticed that this thread has just about 4000 views. Since this has so many views and few responses, I'm going to guess that people are coming here from Google. So, feel free to use that as motivation to write a 'Part 2' for this! Because really, what matters more to you, responses or people actually learning from this content? Just because there's few replies doesn't mean that it's not being used.

Reply

RE: Learn DELPHI with Legolas | Part 1 #5
@"Maxx" ,

thanks for your response. I really appreciate it. Ι seek/try to hear opinions because this helps me to become better. A better person.
And that's why i am a bit sad about this. Due to few responses.

I have not occupied with Java yet. But, i know the C language in a very good level. However, Delphi is a so powerful language.

I have noticed that SEO works very good with HC. Also, if you search, about Delphi tutorials, it's extremely difficult to find something full detailed.
And yes! I will continue this try, with Part 2, Part 3 and Part 4, as i said before on the thread.

Thank you,
Legolas.
[Image: T4OUWZ1.png]


Reply

RE: Learn DELPHI with Legolas | Part 1 #6
This is totally a HQ tutorial.
Thanks for sharing all this information dude!
Keep up the good work!
MASTERING OTHERS IS STRENGTH, MASTERING YOURSELF IS TRUE POWER.

[Image: qJweLN6.jpg]

Reply

RE: Learn DELPHI with Legolas | Part 1 #7
Thank you for this Legolas.
You've put a hell lot of effort into making this tutorial.
You've inspired me to switch to Delphi.
Thank you.
Visual Basic.Net

Private Message me for help

I'm not active because I'm busy with school.

Reply

RE: Learn DELPHI with Legolas | Part 1 #8
Update : 29/8/2014.

I have made many changes in Thread. Now, it looks more beautiful and is more readable. If someone has something to suggest, i'd be glad to hear it.

Thank you ! :Smile:
[Image: T4OUWZ1.png]


Reply

RE: Learn DELPHI with Legolas | Part 1 #9
Well... Im really out of words. Great tutorial. /*applauds*/
This is UQ post - uber-quality.

Reply

RE: Learn DELPHI with Legolas | Part 1 #10
(08-29-2014, 03:27 PM)l4ur15 Wrote: Well... Im really out of words. Great tutorial. /*applauds*/
This is UQ post - uber-quality.

Thank you ! :Smile: I realy appreciate your opinion. Glad you liked it ! :Smile: I will start to work on the other Delphi-Parts soon. Just note, that there is not any similar Delphi-Thread in none forum.
[Image: T4OUWZ1.png]


Reply