Delphi APP opens Door (vi) an approach to the Object Pascal language method

Source: Internet
Author: User

Delphi APP opens Door (vi) an approach to the method of Object Pascal language sharing:Share on FacebookShare on TwitterShare on Google_plusone_sharestated expiry Refer reads: 3442 發表時間:2014/06/10Tags: mobile learning App Delphi XE6 Android IOS

Delphi APP opens Door (v) GPS positioning function << previously

After five weeks, you can write a simple app every week, and everyone can feel the power of Delphi! This prayer is very quick to teach you the core language of Delphi "object pascal", because this series of articles is the "delphi APP to open the door", so there is not too much of the language (on the one hand is afraid that everyone will scare away soon), The pen still wants to be interested in the door to focus. Next, we'll teach you the most common variables, the constant declaration, the type of material, the declaration of the structure, and the basic language of process control, and the rest will be left to one by one in the war.

program annotations

The single line is used with a double backslash//, the Multiline is using {}

This is a single-line solution {1 2 3 This is a multiline registration 4 5          }
Constants, variables

Object Pascal declares that the key to the change is to use Var, for example, to create a i1 variable, which is the integer integer.

var  i1:integer;

If you declare that I1,i2 is an integer, you can use it, separate it.

var  i1,i2:integer;

And the constant key is const, we build a PI variable, the type is double, and the value is 3.14159.

Const  pi:double = 3.14159;
type species

Object Pascal has a wide variety of types, even because it supports multiple platforms and supports various platforms. We will only list the most commonly used form of information for your reference, if you are interested in a complete information type, you can refer to the Embarcadero Variant type chapter.
The basic information type is as follows:

var  i:integer;//integer  s:string;  String  C:char;    character element  d:double;  Floating point numbers  b:boolean;//Bollinger Bands
Declaration of structure Form

The declaration of the structure is the form of the programmer's own information. such as declaring an employee record

Type  temployee = Record    name     : string;//Employee name    Addr     : string;//employee Address    Hour     : Double;//Working hours Number    Employed:boolean;//In the occupation and no  end;

Or declare an array of 1 to 100.

Type  tmyarray = array [1..100] of Integer;
Process Control if process

If process control is probably the most commonly used sentence method in all programming languages, the use of Delphi is as follows

  Usage 1 (single sentence)  if Z > B then    s: = ' Z greater than B ';  Usage 2 (heavy penalty)  if Z > B then    s: = ' Z is greater than B '  //Note this is not necessary;  B THEN begin    S: = ' z greater than B ';  Note that this is to be used;  End else If Z < b then begin    S: = ' Z is less than B ';  Note that this is to be used;  End ELSE BEGIN    S: = "Z is equal to B";    End;
For loop

For is a loop that performs the number of times that can be emerges or descending emerges.

  From 1 to ten for  i:= 1 to ten do begin    sum:= sum + i;  End
  From 10 to 1 for  i:= Downto 1 does begin    sum:= sum + i;  End
and loop

The maximum difference between for and while is the number of times that the for is specified, but the while is executed according to the condition, with the example of 1 plus 10.

  While i<=10 does begin    sum: = sum + i;    I: = i +1;  End
Repeat Loop

While and repeat are the conditions of the loop, and the difference between the two is the first sentence and then execute the line, repeat is the first to execute and then judge.

  Repeat    sum:=sum+i;    i:=i+1;  Until i>10;
Case multiple Select one

If your sentence is to be chosen more than one, you can use the language of case

  Case Imonth of    2,3,4:       showmessage (' Spring ');    5..7:      showmessage (' Summer ');    8..10:      showmessage (' Autumn ');    11..12,1:      showmessage (' Winter ');  else    ShowMessage (' month of misunderstanding ');  End
Program and function

The difference between a program (procedure) and a function (function) is that there is no return value.

  var     name:string;  Procedure Tform1.hello1 (s:string);  Begin    Name: = ' Hello ' + S;   If a passing value is required, declare the change  end externally;  function Tform1.hello2 (s:string): String;  Begin    Result: = ' hello ' + S;////Return String type change  end;  Procedure Tform1.button1click (sender:tobject);  var     s:string;  Begin    s:= ';    Hello1 (' CodeData ');     Direct call to procedure    showmessage (name);    s:= Hello2 (' CodeData '); It is necessary to establish the value of the    showmessage (s);  End

This week is the simplest way to tell the reader about Delphi's basic language, and if you are interested in the Delphi method, you can refer to the official documents for free Embarcadero. In the continuing teachings, if there is any use of the language or use that has not been mentioned, it is also stated in the text.

Continue >> Delphi APP Launch (vii) notification and cloud-side push

Delphi APP opens Door (vi) an approach to the Object Pascal language method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.