程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> Delphi 關鍵字詳解

Delphi 關鍵字詳解

編輯:Delphi

 

absolute
var
  Str: string[];
  StrLen: Byte absolute Str;



begin
  Str := ;
  Edit1.Text := IntToStr(StrLen);
end;

 

abstract


type
  TDemo = class
    private
    protected
      procedure X; virtual; abstract;
    public
      constructor Create;
      destructor Destroy; override;
    published
  end;

 

and
if (a>) and (b>) then


var
  a,b,c: Integer;
begin
  c := (a and b);
end;



if a> and b> then

if a>( and b)> then

if (a>) and (b>) then




 

array


var
  Arr1: array [..] of Integer;


var
  Arr2: array of Integer;


function X(A: array of Integer): Integer;
var
 i: Integer;
begin
  Result := ;
  for i :=  to Length(A)- do
  Result := Result + A[i];
end;

 

as
procedure BtnClick(Sender:TObject);
begin
  (Sender as TButton).Caption := ;
end;


(HTTPRIO as IExp).GetConnection;


var
  i: Integer;
  s: string;
begin
  s := (i as string);
end;

s := string(i);

 

asm
function IntToHex(Value: Integer; Digits: Integer): string;
asm
  CMP  EDX, 
  JBE  @A1
  xor  EDX, EDX
  @A1: PUSH ESI
  MOV  ESI, ESP
  SUB  ESP, 
  PUSH ECX
  MOV  ECX, 
  CALL CvtInt
  MOV  EDX, ESI
  POP  EAX
  CALL System.@LStrFromPCharLen
  ADD  ESP, 
  POP  ESI
end;

 

assembler

function IntToHex(AValue: Int64): string; assembler;

 

automated

type
  TDemo = class
    automated
      Str:WideString;
  end;


type
  TDemo = class
    automated
      Str: AnsiString;
  end


 

begin
procedure X;
begin
  ShowMessage();
end;


for i:= to  do
begin
  sum := sum + i;
  if sum >  then Break;
end;

 

case

function GetDays(AYear,AMonth: Integer): Integer;
begin
  case AMonth of
    ,,,,,,: Result := ;
    ,,,: Result := ;
    : begin
    if IsLeapYear(AYear) then
      Result:=
    else
      Result:=;
    end;
  else
    Result:=;
end;

 

cdecl


int X(int i)
{
  return i*2;
}
function X(i: Integer): Integer; Cdecl; external ;

 

class

type
  ClassDemo = class(TObject)
    private
    public
      constructor Create;
  end;


type
  ClassA = class
    private
    public
      procedure Y;
  end;

type
  ClassB = class(ClassA)
    private
    public
      class procedure X;
  end;

procedure ClassA.Y;
begin
  Self.X;
end;

 

const

const MyFileName = ;
const MyInteger = ;



function X(const i: Integer): string;

 

constructor

type
  ClassDemo = class(TObject)
    private
      fValue: Integer;
    public
      constructor Create;
  end;

constructor ClassDemo.Create;
begin
  fValue := ;
end;

 

contains

package DATAX;
  requires
    rtl, clx;
  contains
    Db, DBLocal, DBXpress;
end.

 

default

type
  ClassDemo = class
    private
      fValue: Integer;
    published
      property Value: Integer read fValue write fValue default ;
  end;


property strings[Index: Integer]: string read GetString write PutString; Default;

 

destructor

type
  ClassDemo = class(TComponent)
    public
      destructor Destroy;override;
  end;



destructor Destroy; overload;

 

dispid



type
  IStringsDisp = dispinterface
    []
    property ControlDefault[Index: Integer]: Olevariant dispid ; default;
    function Count: Integer; dispid ;
    property Item[Index: Integer]: Olevariant dispid ;
    procedure Remove(Index: Integer); dispid ;
    procedure Clear; dispid ;
    function Add(Item: Olevariant): Integer; dispid ;
    function _NewEnum: IUnknown; dispid -;
  end;

 

dispinterface







 

div
var
  a,b,c:Integer;
begin
  a := ; b := ;
  c := a div b; 
end;

 

do


for i :=  to  do sum:=sum+i;


while i <  do
begin
 sum := sum + i;
 Inc(i);
end;


try
 i := StrToInt(s);
except
 on exception do ShowMessage();
end;


with Memo1.Lines do
begin
 Clear;
 Append();
 Append();
end;

 

downto
for i :=  downto  do
  ListBox1.Items.Add(IntToStr(i));


 

dynamic

procedure X(i: Integer); dynamic;

 

else


if a > b then
  c := a
else
  c:=b;


case Tag Of
  :Result:=;
  :Result:=;
  :Result:=;
else
  Result:=;
end;


try
  i := StrToInt(s);
Excpet
  on EZeroDivide do Result := ;
  on EOverflow do Result := ;
else
  Result := ;
end;

 

end




procedure X;
begin
 with Button1 do
 begin
  if Button1.ShowHint then
   Button1.Caption := 
  else
   Button1.Caption := ;
 end;
end;


package DATAX;
  requires
    rtl,
    clx;
  contains Db, DBLocal, DBXpress;
end.

 

except
try
  i := StrToInt(s);
except
  ShowMessage();
end;

 

export

function Add(a,b: Integer): Integer; export;


function Add(a,b: Integer): Integer; stdcall; external ;

 

exports
library Demo;

function X(i: Integer): string; stdcall;
begin
 Result:=IntToStr(i);
end;

exports
 X;

begin
end.


library Demo;

function X(i: Integer): string; overload; stdcall;
begin
 Result := IntToStr(i);
end;

function X(s: string): Integer; overload; stdcall;
begin
 Result := StrToInt(s);
end;

exports
  X(i: Integer) name ,
  X(s: string) name ;

begin
end.

 

external

procedure X(i:Integer);external;


function A(FileName: string): string; external ;


function A(Name: string): string; overload; stdcall; external  name ;
function A(Code: Integer): string; overload; stdcall; external  name ;


 

far

function Add(a,b: Integer): Integer; Far;


function Add(a,b: Integer): Integer; stdcall; external ;

 

file

type
  TPerson = record
    PName: string[];
    PAge: Integer;
  end;
var
  PFile: file of TPerson;

 

finalization


initialization
  ActiveX.OleInitialize(nil);
finalization
  ActiveX.OleUninitialize;

 

finally

try
  Node := Node.GetNext;
  Edit1.Text := Node.Text;
finally
 Node := nil;
end;

 

for
for i :=  to  do sum := sum + i;


for i :=  downto  do Inc(sum);

 

forward

function X(i: Integer): Integer; forward;
procedure Y(s: string); forward;
...
function X;
begin
  Result := i * ;
end;

procedure Y;
begin
  WriteLn(s);
end;


 

function
function X(i: Integer): Integer;


type
 TFun = function(i: Integer): Integer of object;


 

goto


var
 a,b: Integer;
label
 X,Y;
begin
 if a > b then
  goto X
 else
  goto Y;
X:
 WriteLn();
Y:
 WriteLn();
end;

 

if
var
 a,b: Integer;
begin
 a := ; b := ;
 if a>b then
  WriteLn( + IntToStr(a))
 else
  WriteLn( + IntToStr(b));
end;



if a > b then
begin
 WriteLn();
 WriteLn( + IntToStr(a));
 WriteLn( + IntToStr(b));
End
else
 WriteLn();

 

implementation



implementation
  uses frmAbout;
begin
  FormAbout.Show;
end;


 

implements

type
 IMyInterface = interface
  procedure P1;
  procedure P2;
 end;
 TMyImplclass = class
  procedure P1;
  procedure P2;
 end;
 TMyclass = class(TInterfacedObject, IMyInterface)
  FMyImplClass: TMyImplClass;
  property MyImplClass: TMyImplclass read FMyImplclass implements IMyInterface;
  procedure IMyInterface.P1 = MyP1;
  procedure MyP1;
 end;


procedure IMyInterface.P1 = MyP1;

 

in
type
 TCol = (cA,cB,cC);
 TCols = set of TCol;
var
 Cols: TCols;
begin
 Cols := [cA,cB];
 if cA in Cols then
  ShowMessage()
 else
  ShowMessage();
end;


Uses
 Unit1 in ;


var
 s: string;
 sl: TStringList;
begin
 ...
 for s In sl do
 begin
  ShowMessage(s);
 end;
end;

 

index
type
 TForm1 = class(TForm)
 private
  function GetInfo(const Index: Integer): Longint;
  procedure SetInfo(const Index: Integer; const Value: Longint);
 public
  property iLeft:Longint index  read GetInfo write SetInfo;
  property iTop:Longint index  read GetInfo write SetInfo;
  property iWidth:Longint index  read GetInfo write SetInfo;
  property iHeight:Longint index  read GetInfo write SetInfo;
 end;

function TForm1.GetInfo(const Index: Integer): Longint;
begin
 case Index of
  : result := self.Left;
  : Result := self.Top;
  : result := self.Width;
  : result := self.Height;
 end;
end;


property Selected[Index: Integer]: Boolean read GetSelected write SetSelected;

 

inherited
type
 TDemo = class(TComponent)
 public
  constructor Create(AOwner: TComponent); override;
 end;

constructor TDemo.Create(AOwner: TComponent);
begin
 inherited Create(AOwner);
end;


inherited Create(AOwner);

Inherited;

 

initialization


initialization
  ActiveX.OleInitialize(nil);
finalization
  ActiveX.OleUninitialize;

 

inline

function IntToStr(Value: Integer): string;
asm
 InLine;
  PUSH  ESI
  MOV   ESI, ESP
  SUB   ESP, 
  xor   ECX, ECX
  PUSH  EDX
  xor   EDX, EDX
  CALL  CvtInt
  MOV   EDX, ESI
  POP   EAX
  CALL  System.@LStrFromPCharLen
  ADD   ESP, 
  POP   ESI
end;

 

interface



Interface
 uses frmAbout;
var
 FAbout: TFormAbout;
begin
 FAbout := TFormAbout.Create(Self);
 FAbout.Show;
end;




type
 IMalloc = interface(IInterface)
 []
  function Alloc(Size: Integer): Pointer; stdcall;
  function Realloc(P: Pointer; Size: Integer): Pointer; stdcall;
  procedure Free(P: Pointer); stdcall;
  function GetSize(P: Pointer): Integer; stdcall;
  function DidAlloc(P: Pointer): Integer; stdcall;
  procedure HeapMinimize; stdcall;
 end;

 

is
var
 Comp: TComponent;
begin
  ...
 if Comp Is TEdit then
  (Comp as TEdit).Text := ;
end;

 

label
var
 a,b: Integer;
label
 X,Y;
begin
 if a > b then
  goto X
 else
  goto Y;
X:
 WriteLn();
Y:
 WriteLn();
end;

 

library
library Editors;
uses EdInit, EdInOut, EdFormat, EdPrint;
exports
  InitEditors,
  doneEditors name done,
  InsertText name Insert,
  DeleteSelection name Delete,
  FormatSelection,
  PrintSelection name Print,
  SetErrorHandler;
begin
  InitLibrary;
end.

 

message

procedure Refresh(var Msg: TMessageRecordtype); message ID_REFRESH;

procedure Refresh(var Msg: TMessageRecordtype);
begin
  if Chr(Msg.Code) =  then
    ...
  else
    inherited;
end;


 

mod
var
 a,b,c: Integer;
begin
 a := ; b := ;
 c := a mod b; 
end;

 

name


function MessageBox(HWnd: Integer; Text, Caption: PChar; Flags: Integer): Integer; 
  stdcall; external  name ;

 

near

function Add(a,b: Integer): Integer; near;


function Add(a,b: Integer): Integer; stdcall; external ;

 

nil
while Node <> nil do
begin
 ListBox1.Items.Add(Node.Text);
 Node := Node.GetNext;
end;

 

nodefault
type
 TClassA = class
 private
  fValue: Integer;
 published
  property Value: Integer read fValue write fValue default ;
 end;

 TClassB = class(TClassA)
 published
  property Value:Integer read fValue write fValue nodefault;
 end;



 

not
if a > b then

if not(a < b) then


procedure Button1Click(Sender: TObject);
begin
 StatusBar1.Visible := not StatusBar1.Visible;
end;

 

object

type
 ODemoA = object
 end;

 ODemoB = object(ODemoA)
 end;


type
 TMyFun = function(i: Integer): Integer of Object;
 TMyProc = procedure(s: string) of object;


 

of


case Tag Of
 : Result := ;
 : Result := ;
end;


type
 TDemo = class of TComponent;


var
 MyInt: array of Integer;


var
 MyFile: file of Byte;


type
 TCol = (cA,cB,cC);
 TCols = set of TCol;


type
 MyFun = function(I: Integer): Integer of Object;

 

on
try
 i := StrToInt(s);
except
 on E: exception do
  ShowMessage(E.Message);
end;

 

or
if (a>) or (b>) then


var
  a,b,c: Integer;
begin
  c := (a or b);
end;



例如:
if a> or b> then

if a>( or b)> then

if (a>) or (b>) then




 

out


procedure X(out i: Integer; out s: string);
begin
 i := i * ;
 s := s + ;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
 i: Integer;
 s: string;
begin
 i := ;
 s := ;
 X(i,s);
end;

 

overload

function X(i: Integer): string; overload;
function X(s: string): string; overload;



type
 TDemo = class(TComponent)
 public
  procedure CreateWnd(AOwner: TWinControl); overload;
 end;


procedure CreateWnd; 
procedure CreateWnd(AOwner: TWinControl); 



 

override

procedure Create(AOwner: TComponent); override;


type
 TClassA = class
  procedure X; virtual;
 end;

 TClassB = class(TClassA)
  procedure X; override;
 end;


procedure X; 

procedure X; 



 

package

package DATAX;
  requires
    rtl,
    clx;
  contains
    MyUnit in ;
end.

 

packed
type
 TPerson = packed Record
  PName: string[];
  PAge: Integer;
 end;
 MyArray: packed array of PChar;

 

pascal


function X(i: Integer): Integer; Pascal;
begin
 Result := i * ;
end;

 

private

 

procedure
procedure X(i: Integer);


type
 TProc = procedure(i: Integer) of object;


 

program
program Project1;
uses
  Forms,
  Unit1 in  ;

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.

 

property

type
 TDemo = class
 Private
  fValue: Integr;
 Published
  property Value: Integer read fValue write fValue;
 end;


type
 TOnTextChange=procedure (Sender: TObject) of object;
 TDemo = class
 private
  fEvent: TOnTexChange;
 published
  property OntextChange: TOnTextChange read fEvent write fEvent;
 end;

 

protected

 

public

 

published


 

raise

function GetString(i: Integer): string;
begin
 if i <  then
  raise exception.Create();
 Result := IntToStr(i);
end;


try
 i := StrToInt(s);
except
 on E: exception do
  raise exception.Create(E.Message);
end;

 

read
private
 fValue: Integer;
published
 property Value: Integer read fValue;


 

readonly
property ReadOnly;


 

record

type
 TPerson = record
  PName: string[];
  PAge: Integer;
 end;

 

register
function Add(a,b: Integer): Integer; Register; Register


procedure Register;
begin
 RegisterComponents(, [TDemo]);
end;

 

reintroduce


type
 TClassA = class
  procedure X;
 end;
 TClassB = class(TClassA)
  procedure X; reintroduce;
 end;
 TClassC = class(TClassB)
  procedure X(i: Integer); reintroduce;
 end;

 

repeat

i := ;
repeat
 sum := sum + i;
 Inc(i);
until(i >= );

 

requires
package DATAX;
  requires
    rtl,
    clx;
end.

 

resourcestring
ResourceString
 CreateError = ;
 OpenError = ;
 LineTooLong = ;
 ProductName = ;
 SomeResourceString = SomeTrueConstant;

 

safecall

procedure X(s: WideString); safecall;


procedure X(s: PAnsiString);

 

set
type
 TCol = (cA,cB,cC);
 TCols = set of TCol;


var
 Cols: Tcols;
begin
 Cols := Cols + [cA,cB];
end;

 

shl
var
 x: Integer;
begin
 X :=  shl ; 
end;

 

shr
var
 x: Integer;
begin
 X :=  shr ; 
end;

 

stdcall



Library Demo;
function X(i: Integer): Integer; stdcall;
begin
 Result := i * ;
end;
exports
 X;
begin
end.


function X(i: Integer): Integer; stdcall; external ;


 

stored
property Value: string read fValue write fValue stored True;

 

string
var
 Str: string;

 

then
var
 a,b: Integer;
begin
 if a > b then
  WriteLn()
 else
  WriteLn();
end;

 

threadvar

threadvar S: AnsiString;
S := ;
S := ;


 

to
for i :=  to  do
 ListBox1.Items.Add(IntToStr(i));


 

try
try
 i := StrToInt(s);
except
 ShowMessage();
end;

 

type
type
 TDemo = class
 end;


type
 TCol = (cA,cB,cC);
 TInt = Integer;

 

unit
Unit Unit1;
Interface
 uses Classes;
implementation
end.


 

until

i := ;
repeat
 sum := sum + i;
 Inc(i);
until(i >= );

 

uses

Interface
 uses Classes;
Implemention
 uses frmAbout;

 

var
var
 i: Integer;
 s: string;


function X(var i: Integer): Integer;


 

varargs
function printf(Format: PChar): Integer; cdecl; varargs;


 

virtual

procedure X(i: Integer); virtual;

 

while
i := ;
while i <  do
begin
 sum := sum + i;
 Inc(i);
end;

 

with
with Form1.Memo1.Lines do
begin
 Clear;
 Append();
 Append();
 SaveToFile();
end;


Form1.Memo1.Lines.Clear;
Form1.Memo1.Lines.Append();
Form1.Memo1.Lines.Append();
Form1.Memo1.Lines.SaveToFile();

 

write
private
 fValue: Integer;
published
 property Value: Integer write fValue;


 

writeonly
property writeonly;


 

xor
var
 a,b: Integer;
begin
 a := ; b := ;
 if a xor b then
  WriteLn()
 else
  WriteLn();
end;


WriteLn(IntToStr( xor )); 

轉自萬一老師:http://www.cnblogs.com/del/archive/2008/06/23/1228562.html

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved