Delphi 키워드 자세히 1

18227 단어 Delphi
본문은 오렌지.에서 창작한 것으로 판권은 오렌지에 귀속된다
absolute
//             ,                   .
var
Str: string[32];
StrLen: Byte absolute Str;

// StrLen Str .
// 0 , StrLen .
begin
Str := 'abc';
Edit1.Text := IntToStr(StrLen);
end;

 
abstract
//           ,               .
//Abstract Virtual Dynamic , .
// , .
type
TDemo = class
private
protected
procedure X; virtual; abstract;
public
constructor Create;
destructor Destroy; override;
published
end;

 
and
// 、     
if (a>0) and (b>0) then

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

// And , And , .
// :
if a>0 and b>0 then
// :
if a>(0 and b)>0 then
// :
if (a>0) and (b>0) then
// , , .
// a>b>c , Delphi .
// And , .
// , And .

 
array
//Array      ,              .          2 .

//
var
Arr1: array [1..10] of Integer;

// , , SetLength
var
Arr2: array of Integer;

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

 
as
//As               
procedure BtnClick(Sender:TObject);
begin
(Sender as TButton).Caption := 'Clicked';
end;

// , As
(HTTPRIO as IExp).GetConnection;

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

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

 
assembler
//Assembler            ,  80386 .
// Asm :Asm Win32 , Assembler 80x86 , Invoke .
function IntToHex(AValue: Int64): string; assembler;

 
automated
//Automated                  ,              .
//ComObj Automated .
type
TDemo = class
automated
Str:WideString;
end;

// , Str ,
type
TDemo = class
automated
Str: AnsiString;
end
// Str WideString , AnsiString.
// , , automated .

 
begin
//begin                   ,    end      .
procedure X;
begin
ShowMessage('A Demo');
end;

// , If, For, While begin
for i:=1 to 100 do
begin
sum := sum + i;
if sum > 1000 then Break;
end;

 
case
//Case          , Case                ,     ,     ,     .
//Case end , , else .
function GetDays(AYear,AMonth: Integer): Integer;
begin
case AMonth of
1,3,5,7,8,10,12: Result := 31;
4,6,9,11: Result := 30;
2: begin
if IsLeapYear(AYear) then
Result:=29
else
Result:=28;
end;
else
Result:=0;
end;

 
cdecl
//Cdecl          ,      C C++   DLL             .
// C C++ Delphi .
// C++ :
int X(int i)
{
return i*2;
}
//        Demo.dll ,  Delphi       :
function X(i: Integer): Integer; Cdecl; external 'Demo.dll';

 
class
//Class             ,             .
// , Class , .
type
ClassDemo = class(TObject)
private
public
constructor Create;
end;

// class , , :
type
ClassA = class
private
public
procedure Y;
end;

type
ClassB = class(ClassA)
private
public
class procedure X;
end;
// ClassA ClassB X
procedure ClassA.Y;
begin
Self.X;
end;
// class .

 
const
//Const         ,   const               .
// , const .
const MyFileName = 'Delphi';
const MyInteger = 100;

// Const , , .
// const
function X(const i: Integer): string;
// , i .

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

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

 
contains
//Contains         (Package)        .
// Contains , .
package DATAX;
requires
rtl, clx;
contains
Db, DBLocal, DBXpress;
end.

 
default
//Default               
// , .
type
ClassDemo = class
private
fValue: Integer;
published
property Value: Integer read fValue write fValue default 0;
end;

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

 
destructor
//Destructor        ,               .
// , . Destroy .
type
ClassDemo = class(TComponent)
public
destructor Destroy;override;
end;

// TComponent Destroy ,
// , , :
destructor Destroy; overload;

 
dispid
//DispId      DispInterface   ,            .
// DispInterface , ,
// DispId, .
// DispInterface .
type
IStringsDisp = dispinterface
['{EE05DFE2-5549-11D0-9EA9-0020AF3D82DA}']
property ControlDefault[Index: Integer]: Olevariant dispid 0; default;
function Count: Integer; dispid 1;
property Item[Index: Integer]: Olevariant dispid 2;
procedure Remove(Index: Integer); dispid 3;
procedure Clear; dispid 4;
function Add(Item: Olevariant): Integer; dispid 5;
function _NewEnum: IUnknown; dispid -4;
end;

 
dispinterface
//DispInterface              ,                        .
// DispInterface , .
//DispInterface , .
// DispId .
//DispInterface Windows , Linux , .
// , DispInterface.

// DispId

 
div
//Div         .  Div             ,          .
var
a,b,c:Integer;
begin
a := 20; b := 3;
c := a div b; {6}
end;

 
do
//Do     For, While, On, With  ,        

//For :
for i := 1 to 100 do sum:=sum+i;

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

//On ( ):
try
 i := StrToInt(s);
except
 on exception do ShowMessage('Error!');
end;

//With :
with Memo1.Lines do
begin
 Clear;
 Append('abc');
 Append('123');
end;

 
downto
//DownTo     For  ,           .
for i := 100 downto 1 do
ListBox1.Items.Add(IntToStr(i));

// For , To , DownTo .

 
dynamic
//Dynamic           , 
// , ( Virtual).
procedure X(i: Integer); dynamic;

 
else
//else           ,     If, Case On    ,        ,   else   

//If ( If , else ):
if a > b then
c := a
else
c:=b;

//Case :
case Tag Of
1:Result:=1;
2:Result:=2;
3:Result:=3;
else
Result:=0;
end;

//On ( ):
try
i := StrToInt(s);
Excpet
on EZeroDivide do Result := 1;
on EOverflow do Result := 2;
else
Result := 0;
end;

 
end
//End               .
// begin, Case, Class, Interface, Asm, Unit, Package .
// ( ), End .
// ( ), end .
// If else End .
procedure X;
begin
 with Button1 do
 begin
  if Button1.ShowHint then
   Button1.Caption := 'Hinted'
  else
   Button1.Caption := 'Not Hinted';
 end;
end;

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

 
except
//except         ,     try   ,       ,    except    
try
i := StrToInt(s);
except
ShowMessage('Error!');
end;

 
export
//Export         ,          ,               .
// dll . .
function Add(a,b: Integer): Integer; export;

// Demo.exe, ,
function Add(a,b: Integer): Integer; stdcall; external 'Demo.exe';

 
exports
//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 'x1',
X(s: string) name 'x2';

begin
end.

 
external
//External              OBJ    .
{$L Demo.OBJ}
procedure X(i:Integer);external;

// dll , :
function A(FileName: string): string; external 'Demo.dll';

// , .
function A(Name: string): string; overload; stdcall; external 'Demo.dll' name 'A1';
function A(Code: Integer): string; overload; stdcall; external 'Demo.dll' name 'A2';

// External , , .

 
far
//Far         ,            .
// dll . .
function Add(a,b: Integer): Integer; Far;

// Demo.exe, , :
function Add(a,b: Integer): Integer; stdcall; external 'Demo.exe';

 
file
//File            ,         File, 
// File Of , .
type
TPerson = record
PName: string[32];
PAge: Integer;
end;
var
PFile: file of TPerson;

 
finalization
//finalization                   , 
// , .
//finalization OLE .
initialization
ActiveX.OleInitialize(nil);
finalization
ActiveX.OleUninitialize;

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

 
for
//For     For    ,           .
for i := 1 to 100 do sum := sum + i;

// , DownTo
for i := 100 downto 1 do Inc(sum);

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

procedure Y;
begin
WriteLn(s);
end;

// Forward , .

 
function
//Function      
function X(i: Integer): Integer;

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

// , , , .

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

 
if
//If     If    ,          .
var
 a,b: Integer;
begin
 a := 2; b := 3;
 if a>b then
  WriteLn('a=' + IntToStr(a))
 else
  WriteLn('b=' + IntToStr(b));
end;

//If If...Then...else, else .
// If , begin...End .
if a > b then
begin
 WriteLn('a>b');
 WriteLn('a=' + IntToStr(a));
 WriteLn('b=' + IntToStr(b));
End
else
 WriteLn('b>a');

 
implementation
//Implementation           ,         :
//Unit...Interface...implementation...end.
// , implementation .
// implementation , , .
implementation
uses frmAbout;
begin
FormAbout.Show;
end;

// implementation .

 
implements
//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;

// implements , , :
procedure IMyInterface.P1 = MyP1;

좋은 웹페이지 즐겨찾기