1.ä»TurboPascalå°Delphi
ä»TurboPascalå°Delphi
ããç¢éªããææ¯å¨é«ä¸æ¥è§¦pascalè¯è¨ å 为åå NOIçéè¦ é¡ºçæç« çè¦ä½¿ç¨Turbo Pascalæ¥åç¨åºäº åå¹´å æå¼å§æ³çå¦ä½ç¼åWindowsç¨åº åçæå½ç¶çæ¾ä¸Delphi åè§Delphi é¤äºbegin end让æè§å¾åæ亲åå¤ Object Pascaléçå¢å çé¢å对象çè¯æ³å´è®©æå¾æ¯åæ å½æ¶çæå¯æ ¹æ¬ä¸æä»ä¹å«é¢åè¿ç¨ é¢å对象 æå¯æ¶çæ¯ å½å é£äºæè²å®¶ä»¬ é¤äºä¼æ¿çæ¸ åçé£æ¬ç²¾ç®çä¸è½åç²¾ç®çpascalææç §æ¬å®£ç§å¤ ä¼¼ä¹åä¹æ²¡æä»ä¹å®è´¨æ§çå·¥ä½äº ä¼ è¯´ä¸çãTurbo Pascalå¤§å ¨ãæ´æ¯æ å¤å¯å¯» æä»¥å ³äºunit interfaceè¿äºDelphiééå¤å¯è§çå ³é®åæä¹å¾ä¸æç½ æ幸 å ¶åä¸ä¹ æå¾å°ä¸æ¬å为ã计ç®æºåç æ¯ææ¯ãç书 éé¢ç»ç»é½æ¯ç¨Turbo Pascalç¼åçæºä»£ç éè¿å®æè¿ éæç½äºæ©å·²åå¨äºTurbo Pascalä¸unit interfaceçå ³é®åçå«ä¹åç¨æ³ å以Delphiä¸çHelpæ档为æ¶æ å¼å§è¹è·å¦æ¥äº
ããå°è±¡ä¸ å½å Delphiä½å®¶ä¼¼ä¹æ´åç±ç¼ååºç¨å®ä¾ç±»çææ¯ä¹¦ç± è³äºè¯æ³è¿ç§ä¸è¥¿ 没æå 个人æ¿æå¤å»æ¶å å³ä½¿ä¹¦ä¸å¿ é¡»è°å ä¹æ¯å¯¥å¯¥æ°ç¬ ååå¸¦è¿ æè å¹²èä¸ææ¬ä¹¦ç±»ä¼¼ 对Object Pascalè¯æ³è®²è§£æ好 ææå¨çææå°±ç®ãDelphi å¼å人åæåãäº è¿æ¬ä¹¦è³ä»ä¹æ¯å¤åæ¨å´ç ä½ä¸å¦ä»æ³æ»¥çC++书ç±ç¸æ¯ Delphiä»ç¶éè²è®¸å¤ ä¹é¾æªå¾å¤æ°æç¹å«æ¯ä»æ¥æ²¡ææ¥è§¦è¿pascalè¯è¨çæ°æ å¨å¦ä¹ Object Pascalæ¶ä¼éå°ä¸å°å°é¾ èªå·±çæè§æ¯ å¨ä»Turbo PascalåDelphiè¿æ¸¡çè¿ç¨ä¸ ç±äºæ²¡ææ£ç¡®çæå¼ èµ°äºå¾å¤å¼¯è·¯ ç±äºæ²¡ææ£ç¡®çæ¡¥æ¢ å¿ é¡»è¦ä¸æ¥å®ç°å¤§è·¨è¶ æ以 å¨è¿é ææåºèªå·±æ¾ç»éè§çæ²å£ è·¯æ æ§ç»åºæèªå·±ç认è¯åæ»ç» å¸æç»å ¥é¨çåå¦ä»¬ä¸äºå¸®å© æä¸æç®è¯¦ç»ä»ç»è¯æ³ç¥è¯ 并åè®¾ä½ å·²ç»æä¸ç¹pascalè¯è¨åé¢å对象æ¦å¿µçåºç¡ è¦æ³å¦ä¹ ç¸å ³è¯¦ç»ç¥è¯ ææ¨èåä½ä¸å®è¦é 读ãDelphiå¼å人åæåãåDelphi Helpææ¡£ä¸çç¸å ³ç« è
ããè®°å½ä½åç±»
ããä¹ æ¯äºå¨ä¸ä¸ªProgram模åå åå®ææé¢åè¿ç¨ä»£ç çæ æå 天çæ¶é´ä¸ç´æªè½å½»åºæç½å¨éUnit模åä¸ é继æ¿çèªå®ä¹ç±»çæ¡æ¶ è¯æ³æ¯å¦ä½ç VCLæºä»£ç è½ç¶ç»å ¸ å´è¿äºç¹æ ä¸è½è®©æè¿ éææ¡æ ¹æ¬ æéè¦ä¸ä¸ªæç®ååæè½è¯´æé®é¢ å®æ´çå¯è¿è¡ç代ç è¦äºæ å¤å¯»æ±çæ¡ åªå¥½äº²èªå¨æ æ¢ç´¢å¯¹åºå ³ç³» ç»æå ¶ä¸ä¸¤æ®µä»£ç
ããprogram TP;ãã{ æ¬ä»£ç å¨Turbo Pascal ä¸ç¼è¯éè¿}ããtypeããMyRecord = record{ }ããend;
ããvarããMR: MyRecord;ããprocedure Procedure ;ããbeginãã{ Procedure Code}ããend;ãã{ =========== main ===========}ããbeginãã{ 以è¿ä¸ªbegin为æ å¿ ä¸»ç¨åºå¼å§ å ¶ä½ç¨ç¸å½äºC/C++ä¸çmainå½æ°}ããProcedure ;ããend
ããä¸é¢æ¯ä¸æ®µåå ¶ç®åçå å«è®°å½ç±»å声æåè¿ç¨å£°æç代ç äºè åºæ¬è§åå¦ä¸ ç¨æ·èªå®ä¹çæ°æ®ç±»å éè¦æ¾å¨ä»¥ä¿çå type å¼å¤´ç代ç æ®µä¸ è¿ç¨(procedure)åå½æ°(function)è¦æ¾å¨ä»¥ä¿çå var å¼å¤´ç代ç æ®µä¸ æåä¸ä¸ªå¤¹å¨beginåendé´ç代ç 段æ¯ä¸»ç¨åºçå¼å§ ä¹å°±æ¯æ´ä¸ªç¨åºçå ¥å£ ä½ç¨ç¸å½äºC/C++éçmainå½æ° 请注æ åªæå¨ä»¥programä¿çåå¼å¤´ç代ç 模åä¸ è¿ä¸ªbeginåendæå ·æç¨åºå ¥å£çä½ç¨
ããå¦å¤ å¨Turbo Pascalä¸å·²ç»æ¯æåå§çé¢å对象 å®ç声æå ³é®åæ¯Object ä¸ç°å¨æ们常è§çClassä¸å è¯æ³å¦ä¸ ããããobjectããField;ããField;ãã ããMethod;ããMethod;ããend;
ããMethodå 许以ä¸å ç§å½¢å¼ ãããprocedure MethodName(:type);
ããæè function MethodName(:type):type;
ããæè constructor MethodName(: type [;:type]); [virtual];
ããæè destructor MethodName[(: type)];[virtual];
ããä¸éç æé å½æ°åææå½æ°é½æ¯ævirtual å¨æé å½æ°ä¸ è¿æä¸ä¸ªæç¨çä¸è¥¿æ¯Failå½æ° å½æé å½æ°çåå§åå¤±è´¥æ¶ å®å¯ä»¥ç¨æ¥éæ¾å·²ç»åé çèµæº éæ¾çæ¯ Objectéé¢è¿æ²¡æåºåç§æå ±æ æ¥ä¸æ¥ç代ç æ¯Turbo PascalçHelpææ¡£ä¸ å ³äºFailå½æ°çæ¼ç¤ºä»£ç å¯ä»¥è®©å¤§å®¶å¯¹æ¤æ个è¾æ·±çè®¤è¯ Turbo Pascalå´æ¯æ¯å¾å¼ºå¤§åä¼ç§ç
ããtypeããPBase = ^TBase;ããTBase = object(TObject) { å¨è¿é就已ç»åºç°Tobjectäº æ¯ä¸æ¯å¾äº²åï¼}ããconstructor Init(FailMe: Boolean);ããend;
ããPDerived = ^TDerived;ããTDerived = object(TBase)ããconstructor Init(FailMe: Boolean);ããend;
ããconstructor TBase Init(FailMe: Boolean);ããbeginããinherited Init;ããif FailMe then Fail;ããend;ããconstructor TDerived Init(FailMe: Boolean);ããbeginããif not inherited Init(FailMe) then ãã{ å¤æç¶ç±»çåå§åæ¯å¦æå}ãã{ Ancestor failed to construct we must fail too }ããFail;ãã{ Otherwise proceed with construction }ãã{ }ããend;ããvarããP: PObject;ããX: Boolean;ããbeginããfor X := False to True doããbeginããP := New(PDerived Init(X));ããif P <> nil thenããbeginããwriteln( Object constructed sucessfully );ããDispose(P Done);ããendããelseããwriteln( Object failed to construct );ããend;ããend ããåå°Delphiä¸ åçä¸é¢ç代ç ããããprogram Delphi;ãã{ 代ç å¨Delphi ä¸ç¼è¯éè¿}ãã{ $APPTYPE CONSOLE}ããusesããSysUtils;ããtypeããTMyClass = class(TObject)ããpublicããconstructor Create;ããprocedure PrintClassName;ããprivateããClassName: string;ããend;ããvarããMyClass: TMyClass;ããconstructor TMyClass Create;ããbeginããClassName := TMyClass ;ããend;ããprocedure TMyClass PrintClassName;ããbeginããwriteln(ClassName);ããend;ãã{ =========== main ===========}ããbeginããMyClass := TMyClass Create;ããMyClass PrintClassName;ããMyClass Free;ããreadln;ããend
ããç±»ä½ä¸ºç¨æ·èªå®ä¹çä¸ç§æ°æ®ç±»å å ¶å£°æçè§å æåå½æ° è¿ç¨çå®ç°æ¹æ³é½ç¬¦åç»å ¸ Pascalçåºæ¬è§å å¯ä¸ä¸åçæ¯ä¿çååäº ä»è®°å½ä½åæäºç±»ï¼è¯¦ç»æ¯è¾ä»£ç ç»æåè¯æ³è§åï¼ è¿ä¹è¯´æObject Pascalæ¯å¨ç»å ¸Pascalçåºç¡ä¸è¿è¡äºé¢å对象å 容çè¯æ³æ©å å½ç¶ å é¨çè¿è¡æºå¶å¹¶æ²¡æ表é¢è¯æ³æ©å è¿ä¹è½»æ¾ å¯é£æ¯ç¼è¯å¨çäºæ å¨è¿é æ们å®å ¨ä¸ç¨çä¼ å·®ç¹å¿è®°åè¯è¯»è æä¹è°è¯ä¸é¢ç代ç äº å¨IDEç¯å¢ä¸»èåééæ© File | New | Other å¨New Item项ééæ©Console Application è¿æ¶åºç°äºä»£ç ç¼è¾æ¡ åå°ä¸é¢ç代ç è´´å ¥ F å®æï¼ãã代ç å ç{ $APPTYPE CONSOLE}æ¯ä¸ä¸ªç¼è¯å¼å ³ å®åè¯ç¼è¯å¨ è¿æ¯æ§å¶å°ç¨åº å¨æ ¼å¼ä¸å®ä¸æ³¨éçå·®å«å°±æ¯é£ä¸ª $ ç¬¦å· TMyClass = class(TObject)å¯ä»¥ç®å为
ããTMyClass = class 表示TMyClassç±»ä»TObject类继æ¿èæ¥ TObjectæ¯Delpiä¸ææ对象çç¥å è¿ä¹æ¯ä¸ºä»ä¹æå¨ä»£ç ä¸æ²¡æ声æDestroyè¿ç¨å´ä»ç¶è½å¤ä½¿ç¨çåå Delphiä¸ç±»çæé å¾æ趣 请注æMyClass := TMyClass Createè¿ä¸å¥ è¿ä¸C++ä¸å readln使ç¨åºåé¡¿ä¸æ¥ ç´å°ç¨æ·æä¸å车é®æç»æç¨åºéåº æ´å¤è¯¦ç»å 容请åèãDelphiå¼å人åæåã è
ããä¸é¢ä¸¤æ®µä»£ç ç¸äºå¯¹åº è½ç¶å¾ç®å ä¸è¿æå´è®¤ä¸ºä»ä»¬å¨æç§ç¨åº¦ä¸å¾å®¹æ让åå¦åç°ç±ç»å ¸PascalåObject Pascalè¿æ¸¡çä¸äºæ¹æ³ 对Object Pascalçç±»å®ä¹è¯æ³æ个åæ¥äºè§£ è¿æ¯å¾éè¦çä¸æ¥ å½åæè¦æ¯è½å¤çå°è¿ä¸¤æ®µä»£ç æ许è½å°æµªè´¹å¾å¤æ¶é´äº
ããunit模å
ããå¨Turbo PascalçHelpææ¡£é æ¯è¿æ ·è¯´æunitåè½ç Units are the basis 粮仓指标源码of modular programming inBorland Pascal You use units to createlibraries and to divide large programs into logically related modules ä¼ ç»ä¸ æ们é½å°ææ代ç éä¸å¨ä¸ä¸ªprogram模åä¸ å¯æ¯é¢å¯¹æ´å å¤æçåè½ä»£ç æ£ç¡®çåååè½å°è£ åè½å¯¹ä»£ç 管çå以åçç»´æ¤æçéè¦çä½ç¨ è使ç¨unit模åæ£å¥½è§£å³äºè¿äºé®é¢ å ¶è¯æ³è§åå¦ä¸
ããunit identifier; { Heading }ããinterface { Public symbols }:ããuses { Uses clause }ããconst { Constants }ããtype { Types }ããvar { Variables }ããprocedure { Procedures }ããfunction { Functions }ããimplementation { Private symbols }:ããuses { Uses clause }ããlabel { Labels }ããconst { Constants }ããtype { Types }ããvar { Variables }ããprocedure { Procedures}ããfunction { Functions }ããbegin { Initialization }ããstatement; { Statements }ããstatementããend
ããInterfaceé¨åç¨æ¥å£°æ对å¤æ¥å£ ä¹å°±æ¯å¯ä»¥è¢«å¤é¨å¼ç¨è¯¥æ件çç¨åºä½¿ç¨çå½æ°åè¿ç¨ implementationé¨åå å«æ¥å£é¨å声æçåç§å½æ° è¿ç¨å ·ä½å®ç°ç代ç beginä¸ç´å°æåçend ä¹é´é½æ¯åå§åé¨å å¯ä»¥ä¸ºæ¬unitå çåç§åé è¿ç¨ å½æ°åå§å å¦æ没æå 容éè¦åå§å é£ä¹beginå¯ä»¥çç¥ ä½end å¿ é¡»åå¨
ããå¨Delphiä¸ç»å ¸Pascalä¸çunité¨åæäºåå¨ è¯·çæ¥æºäºDelphi Helpææ¡£ç说æ ããunit Unit ;ããinterfaceããusesãã{ List of units goes here }ãã{ Interface section goes here }ããimplementationããuses ãã{ List of units goes here }ãã{ Implementation section goes here }
ããinitializationãã{ Initialization section goes here }ããfinalizationãã{ Finalization section goes here }ããend ããå¯è§Initializationé¨åçå ³é®åbegin 被Initializationåä»£äº å¹¶ä¸å¢å äºä¸ä¸ªfinalizationé¨å Initializationé¨åç代ç å¯ä»¥è¿æ ·å ããinitializationããbeginãã{ do somethingâ¦}ããend;ããä¹å¯ä»¥è¿æ ·å ããinitializationãã{ do somethingâ¦}ããfinalizationé¨åçåè½ æç¹ç±»ä¼¼äºææå½æ° å®ä¸»è¦é对æ¬unit模åä¸initializationé¨ååå§åçèµæºè¿è¡éæ¾ å¹¶ä¸æ¯å¨ç¨åºç»ææ¶è¿è¡ å¦æç¨åºä»¥Haltè¿ç¨ç»æäº è¯¥é¨åçç¨åºå°ä¸è½æ§è¡
ããUnit模åä¸çinterfaceçå ³é®ååç»æåçä¼¼ä¹æäºéå¶ç¨åºåçèªç±åº¦ ä½ä¹æ£æ¯è¿ç§è¯æ³è§å®ä½ç°åºPascalè¯è¨ç严谨åä¼ç¾ 为åå°ç¨åºåºéçå çååºä¿è¯ ããprogramç¸å½æç« çæ纲æé¢ unitåæ¯æç« çåä¸ªæ®µè½ Delphié program模åå å«å¨ prjæä»¶ä¸ unit模åå å«å¨ä¼ ç»ç pasæä»¶ä¸ è¿å°±æ¯ä¸ºä»ä¹å¨Delphiä¸æ们ç»å¸¸é¢å¯¹çæ¯ä¸ºå个çªå£æå¡çunit模å èéå¨ä¸ä¸ªprogramä¸åå®ææ代ç ä¸è¿æå¨DelpiçHelpä¸çå°è¿æ ·ä¸å¥è¯ In traditional Pascal programming all source code including the main program is stored in pas files ä¸ç¥éè¿ç®æèè§åº¦ä¸åè¿æ¯ç®bug æ¯ç«è¿ç§è¯æ³å¹¶éDelphiä¸ææ Turbo Pascalç¨åºåä¹ä¸ç´å¨éç¨è¿ç§æ¹æ³ç»ç»ç¨åºç»æ ããç»åºä¸ä¸ªç®åçinitializationä¾å å¨èåä¸éæ©File | New | Application åå¨çªä½ä¸æ¾ç½®ä¸ä¸ªæé® åå»è¯¥æé®ç¼åå®çClickäºä»¶å¤ç代ç å®æ´ä»£ç å¦ä¸
ããunit Unit ;ããinterfaceããusesããWindows Messages SysUtils Variants Classes Graphics Controls Forms ããDialogs StdCtrls;ããtypeããTForm = class(TForm)ããButton : TButton;ããprocedure Button Click(Sender: TObject);ãã privateãã{ Private declarations }ããpublicãã{ Public declarations }ããend;
ããvarããForm : TForm ;ããMsg: string;ããimplementationãã{ $R * dfm}ããprocedure TForm Button Click(Sender: TObject);ããbeginããShowMessage(Msg);ããMsg := second ;ããend;ããinitializationããMsg := first ;ããend
ãã以ä¸æè¿° æ¯è¿æ¸¡ä¸ä¸¤ä¸ªåºæ¬çéè¦é®é¢ å¼æå®ä»¬æ¹å¯åæ¥æç½èªå·±ä¸ºä»ä¹è¦è¿æ ·ç¼å代ç 该å¨åªéç¼å代ç å¦ä½æ©å±ä»£ç åè½ ããæ¨èçåè书ç±
ããDelphiåè书ç±
ãããDelphi å¼å人åæåãæºæ¢°å·¥ä¸åºç社
ãããInside VCLãæç»´ çµåå·¥ä¸åºç社
ãããDelphi深度åé©ãé宽达 ç§å¦åºç社
ãããPascalç²¾è¦ãç½ç»ä¸è½½çµåçããWindowsåè书ç±
ãããProgramming WindowsãCharles Petzold
ãããWindows å¼å人åæåãä¸å½æ°´å©æ°´çµåºç社
ããDelphiç»ä»¶åè书æææ¶æ²¡æåç°ç¹å«å¥½ç å¹³æ¶æ主è¦ä¾é 论å æºä»£ç ããDelphièªå¸¦çDemoåææ¡£æ¥å¦ä¹ ç»ä»¶ç使ç¨
ããç°å¨æä¸äºå¤§å¦åæ¶äºPascalè¯è¨è¯¾ç¨ å»å¹´çACM大èµä¹åæ¶äºPascalè¯è¨çä½¿ç¨ ä¸ç¦å¿å¯ å¯èæè²æ²¡æ人åäº è¿äºé½ä½¿å¾Delphiå¨å¦çä¸çå¤å¢æ´å è°é¾ å¨å½å çDelphi论åä¸ å¸¸å¸¸è§å°è®¸å¤åååç¨åºåå¨äº«åDelphiçå¿«éå¼åçæ¶å å´å·´éè¿å¨è´£å¤Delphiåè½å¤ªå¼± ä¸è½æä»ä¹åºå±å¼å çè³ç´æ¥è´£æªPascalè¯è¨ æ®ä¸ç¥ å¨Dos年代 æå¤å°èå软件使ç¨Pascalå¼ååºæ¥çå¢ æå¤å°åºå±æ§å¶ç¨åºæçPascalç身影å¢ï¼ç°å¨ææ头ä¸è¿æPascalç¼åçç æ¯ä»£ç åç æ¯ä»£ç ICè¯çæ§å¶ä»£ç
ããæ许æ£æ¯DelphiçRADè½åéä½äºç¨åºå¼åçé¨æ§ 让å¾å¤åååè¿å ¥äºç¨åºç RADå¼åèè½äºè®¸å¤åååç¼ç¨è ï¼ç§°å¼ä»ä»¬ä¸ºç¨åºåæ许ç¨æ¬ ç«åï¼çç¼ç ä½æ¯å½å çæè²çåæ ·æçä¸å¯æ¨å¸ç责任 é修课å¼VBçä¸å° 讲Delphiçå¾å° ææ¾ç»è¿éå°è¿ä¸ä¸ªä»å¿åºéå°±ç§ä¸èµ·Delphi ä¸å»è°è®ºçèå¸ èäºå®ä¸ä»æ ¹æ¬å°±æ²¡æç¨è¿Delphi æç°å¨å¸¸å»å¤å½ç½ç« åç°å½å 被äºè®ºä¸ä¼çé®é¢ å¨å½å¤æ©å°±æ人å¨å 并ä¸åçé常æ£
lishixinzhi/Article/program/Delphi//