![]() |
|
Learn DELPHI with Legolas | Part 1 - Printable Version +- Sinisterly (https://sinister.li) +-- Forum: Coding (https://sinister.li/Forum-Coding) +--- Forum: Coding (https://sinister.li/Forum-Coding--71) +--- Thread: Learn DELPHI with Legolas | Part 1 (/Thread-Learn-DELPHI-with-Legolas-Part-1) |
Learn DELPHI with Legolas | Part 1 - Legolas - 06-27-2014 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. ![]() 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 :
Advantages of Delphi
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
Identifiers of Delphi
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
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]
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]
Datatypes ![]()
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 := expressionCode: //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 typeWarning: 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 MainProgram 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 :
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. RE: Learn DELPHI with Legolas | Part 1 - Legolas - 06-27-2014 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: RE: Learn DELPHI with Legolas | Part 1 - Psycho_Coder - 06-27-2014 Added tutorial tag. RE: Learn DELPHI with Legolas | Part 1 - Spirit - 07-26-2014 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. RE: Learn DELPHI with Legolas | Part 1 - Legolas - 07-27-2014 @"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. RE: Learn DELPHI with Legolas | Part 1 - L0aD1nG - 07-27-2014 This is totally a HQ tutorial. Thanks for sharing all this information dude! Keep up the good work! RE: Learn DELPHI with Legolas | Part 1 - TheDeceptionist - 07-28-2014 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. RE: Learn DELPHI with Legolas | Part 1 - Legolas - 08-29-2014 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: RE: Learn DELPHI with Legolas | Part 1 - l4ur15 - 08-29-2014 Well... Im really out of words. Great tutorial. /*applauds*/ This is UQ post - uber-quality. RE: Learn DELPHI with Legolas | Part 1 - Legolas - 08-29-2014 (08-29-2014, 03:27 PM)l4ur15 Wrote: Well... Im really out of words. Great tutorial. /*applauds*/ 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. |