delphi基础知识.ppt_第1页
delphi基础知识.ppt_第2页
delphi基础知识.ppt_第3页
delphi基础知识.ppt_第4页
delphi基础知识.ppt_第5页
已阅读5页,还剩27页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、2011.07,DELPHI基础知识,delphi历史,Delphi1:1995年 Delphi6:2001年 Delphi2007:CodeGear,2007年 Delphi XE2 Pulsar:embarcadero ,2011年 TIOBE:11-14,注释, Comment using curly braces (* Comment using paren and asterisk *) / double backslash comment,变量 常量,var i: Integer = 10; S: string = Hello world; D: Double = 3.141579

2、; const ADecimalNumber = 3.14;,操作符1,赋值 := Number1 := 5; 比较 =、=、 if x = y then DoSomething if x y then DoSomething 逻辑 not、and、or if (Condition 1) and (Condition 2) then DoSomething; while (Condition 1) or (Condition 2) do DoSomething; if not (condition) then (do something);,操作符2,算术 +、-、*、/、div、mod 位操

3、作 and、not、or、xor、shl、shr 自增自减过程 Inc()、Dec(),数据类型1,ShortInt: 8-bit 有符号整数 Byte:8-bit 无符号整数 SmallInt:16-bit 有符号整数 Word:16-bit 无符号整数 Integer、Longint: 32-bit 有符号整数 Cardinal、LongWord : 32-bit无符号整数 Int64:64-bit 有符号整数 Single:4-byte 浮点数 Double:8-byte 浮点数,数据类型2,Extended:10-byte 浮点数 TDateTime:8-byte 日期,单位 天 Va

4、riant、OleVariant:变体类型 Char:1-byte 字符 WideChar:2-byte 字符 AnsiString:动态字符串 WideString :动态宽字符串 Boolean:布尔型 PChar:NULL结尾字符串,动态内存分配,分配释放 AllocMem() FreeMem() GlobalAlloc() GlobalFree() GetMem() FreeMem() New() Dispose() StrAlloc() StrDispose() StrNew() StrDispose() VirtualAlloc() VirtualFree(),自定义类型1,数组

5、var A: array28.30 of Integer; A1: array1.2, 1.2 of Integer; i: Integer; begin for i := Low(A) to High(A) do Ai := i; end;,自定义类型2,动态数组 SA: array of string; SetLength(SA, 33); SA := nil;,自定义类型3,结构 Type MyRec = record i: Integer; d: Double; end; type TVariantRecord = record NullStrField: PChar; IntFiel

6、d: Integer; case Integer of 0: (D: Double); 1: (I: Integer); 2: (C: char); end;,自定义类型4,集合 type TCharSet = set of char; / possible members: #0 - #255 TEnum = (Monday, Tuesday, Wednesday, Thursday, Friday); TEnumSet = set of TEnum; / can contain any combination of TEnum members TSubrangeSet = set of 1

7、.10; / possible members: 1 - 10 TAlphaSet = set of A.z; / possible members: A - z AlphaSet := ; / Empty; no elements if S in CharSet then do something; Include(CharSet, a); / add a to set CharSet := CharSet + b; / add b to set Exclude(CharSet, x); / remove x from set CharSet := CharSet - y, z; / rem

8、ove y and z from set if a, b, c * CharSet = a, b, c then,自定义类型5,对象 Type TChildObject = class(TParentObject); SomeVar: Integer; procedure SomeProc; end;,自定义类型6,指针 Type PInt = Integer; PFoo = Foo; / PFoo is a pointer to a foo type Foo = record / A record type GobbledyGook: string; Snarf: Real; end; va

9、r P: Pointer; / Untyped pointer P2: PFoo; / Instance of PFoo,流程控制1,IF if x =100 then SomeFunction else if x = 200 then SomeOtherFunction else begin SomethingElse; Entirely; end;,流程控制2,CASE case SomeIntegerVariable of 101 : DoSomething; 202 : begin DoSomething; DoSomethingElse; end; 303 : DoAnotherTh

10、ing; else DoTheDefault; end;,流程控制3,FOR var I, X: Integer; begin X := 0; for I := 1 to 10 do inc(X, I); end.,流程控制4,WHILE var f: TextFile; / a text file s: string; begin AssignFile(f, foo.txt); Reset(f); while not EOF(f) do begin readln(f, S); writeln(S); end; CloseFile(f); end.,流程控制5,REPEAT var x: In

11、teger; begin X := 1; repeat inc(x); until x 100; end.,流程控制6,BREAK var i: Integer; begin for i := 1 to 1000000 do begin MessageBeep(0); / make the computer beep if i = 5 then Break; end; end;,流程控制7,CONTINUE var i: Integer; begin for i := 1 to 3 do begin writeln(i, . Before continue); if i = 1 then Co

12、ntinue; writeln(i, . After continue); end; end;,函数过程参数,传值 procedure Foo(s: string); 传引用 procedure ChangeMe(var x: longint); 不可变参数 procedure Goon(const s: string); 开放数组 function AddEmUp(A: array of Integer): Integer;,单元,Unit FooBar; interface uses BarFoo; public declarations here implementation uses

13、BarFly; private declarations here initialization unit initialization here finalization unit clean-up here end.,面向对象,封装Encapsulation 继承Inheritance 多态Polymorphism 字段 Field 方法Method 属性Property,类,TObject = class constructor Create; procedure Free; destructor Destroy; virtual; end; TFoo = class procedure

14、 IAmAStatic; procedure IAmAVirtual; virtual; procedure IAmADynamic; dynamic; end; var FooObject: TFoo; FooObject := TFoo.Create; FooObject.Free;,属性,TMyObject = class private SomeValue: Integer; procedure SetSomeValue(AValue: Integer); public property Value: Integer read SomeValue write SetSomeValue;

15、 end;,可见性,TSomeObject = class private/私有 APrivateVariable: Integer; AnotherPrivateVariable: Boolean; protected/单元内或子类 procedure AProtectedProcedure; function ProtectMe: Byte; public/公开 constructor APublicContructor; destructor APublicKiller; published/公开 运行时信息 property AProperty read APrivateVariabl

16、e write APrivateVariable; end;,接口1,type IUnknown = interface 00000000-0000-0000-C000-000000000046/GUID function QueryInterface(const IID: TGUID; out Obj): Integer; stdcall; function _AddRef: Integer; stdcall; function _Release: Integer; stdcall; end; IFoo = interface 2137BF60-AA33-11D0-A9BF-9A4537A42701 function F1: Integer; end; IBar = interface(IFoo) 2137BF61-AA33-11D0-A9BF-9A4537A42701 function F2: Integer; end;,接口2,type TFooBar = class(TInterfacedObject, IFoo, IBar) function F1: Integer; function F2: Integer; end; var FB: TFooBar; F: IFoo;

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

最新文档

评论

0/150

提交评论