C + + Builder experience in the use of (turn)

  C + + Builder experience in the use of C + + is Builder3.0 Borland (now renamed the Insprise) was launched in 1998 based on a new generation of the C language RAD development tools.    C + + Builder3.0 the advent of the broad masses of the C language-loving users was as good as a Christian.    Windows because in the past, not a true based on the C language Visual Programming Language.    If you would like to use this type of VB or Delphi visual programming language to program, you have to revisit it again Basic or Pascal language, not the same as the C language can be flexible application of the guideline, not a "+ +" ,"–" such a lovely operation, not a word to use if all the C language as handy.    All these problems have now disappeared.    C + + not only supports traditional Builder3.0 C language, and also supports Borland's OWL and Microsoft's MFC.    It can be said that Builder3.0 C + + under Windows is the most powerful C-language compiler.    Because C + + Builder3.0 come out soon, the information is not many, the following combination of the use of the author to talk about some experiences and understanding. 
  A dynamic form called Form 

  By default, the File / Add NewForm generate income in the form of project documents have "AutoCreate" (created automatically) features.    That is, as long as the procedures and forms to exist in the memory, regardless of whether it is called the present.    This is the form of generally applicable to the relatively fixed form attributes, often called the situation.    The advantage is speed disadvantage is that the occupation of memory.    In the actual design process will be met dialog function of a large number of similar form, they used to show state or input information, only to call in the proceedings to complete its functions on the trip, no permanent memory.    Then can choose Project / Options / Forms, "Auto - Createforms" column corresponding form, such as Form1, and used the ">" button to move to the "Availableforms" column, and in the process will take the form of the Calling , and by adding the following sentence: 

  TForm1 * myform = newTForm1 (this); 

  Myform-> ShowModal (); 

  Deletemyform; 

  Form Form1 only when the call is transferred to the memory needs, calling upon completion, which uses delete removed from the memory.    This procedure can reduce the memory resources of the occupier. 

  Second, the method of traversing form controls 

  To access or modify the form of controls, very simple to TEdit for example: 

  Edit1-> Text = ""; 

  Edit2-> Text = ""; 

  But if there are a dozen like form Edit1 such controls, and the need for the same initialization, using the above method to carry out one by one, not trouble!    It is necessary to grasp control form traversal methods.    In introducing the method before, let us first try to understand what form of Components and Controls Form attributes.    See Table 1. 

  Table 1 

  Property Type Description 
  ComponentCountInt current Form on the total number of all types of controls 
  * Form ComponentsTCompont currently on an array of controls at all 
  ControlCountInt current Form on a sub-regional control on the total number of all types 
  * Form ControlsTControl currently on a sub-regional at all controls array 

  Figure 1 as an example to (abbreviated) that the Form1 ComponentCount = 6, and the Panel1 ControlCount = 4., 

  Of which: an array of objects 

  Components [0] Panel1 

  Components [1] Label1 

  Components [2] Edit1 

  Components [3] Label2 

  Components [4] Edit2 

  Components [5] Button1 

  Object Array 

  Controls [0] Label1 

  Controls [1] Edit1 

  Controls [2] Label2 

  Controls [3] Edit2 

  Below this code completed a Panel1 all Ergodic TEdit control initialization.    Readers slightly modified, and other controls can be carried out on the traverse.    There is a small skills, we need to initialize the control placed in a Panel1, do not initialize the control and separate, and it is easy programming. 

  AnsiStringnamestring = "TEdit"; 

  For (inti = 1; iControlCount; i + +) 

  ( 

  If (Panel1-> Controls [i] -> 

  ClassNameIs (namestring)) 

  ( 

  TEdit * p = dynamic_cast 

  (Panel1-> Controls [i]); 

  P-> Text = ""; 

  ) 

  ) 

  Third, use the Enter key focus switching control method 

  In the Windows environment, to obtain control of a focus on the controls can be used in the mouse click or by the Tab key to move the focus on the controls.    This control method of switching the focus sometimes not with the user's habits.    On a map, users hope to use the Enter key, control focus from Edit1 switch to Edit2.    To achieve this function Nuojiechu WinAPI function SendMessage to complete.    Method: The first set Form1 KeyPreview property to true, then the OnKeyPress incident Form1 add the following code.    In this way, users can press Enter, the key focus, by definition, good control Taborder order to move! 

  Void__fastcallTForm1:: 

  FormKeyPress (TObject * Sender, char & Key) 

  ( 

  If (Key == VK_RETURN) 

  ( 

  SendMessage (this-> Handle, WM_NEXTDLGCTL, 0,0); 

  Key = 0; 

  ) 

  ) 

  Fourth, as with the text color TStringGrid 

  — TStringGrid C + + Builder is available to users of a character grid control.    The fly in the ointment is that it did not provide the elements were modified font color, size method.    In fact, for TStringGrid achieve this function, just a little handle on the process up.    Since the definition is a two-dimensional array cellbuf its subscript and mesh out to one-to-one for the records of the mesh color, text, and other information. 

  StructCellStru 

  ( 

  AnsiStringmsg; / / text messages 

  TColorcolor; / / text color 

  ); 

  CellStrucellbuf [] [MAXCOL MAXROW]; 

  — Cellbuf initialization, and then in the characters Grid Control StringGrid1 OnDrawCell response to the incident, by adding the following code can be. 

  Void__fastcallTForm1:: StringGrid1DrawCell 

  (TObject * Sender, intCol, 

  IntRow, TRect & Rect, TGridDrawStateState) 

  ( 

  StringGrid1-> Canvas-> Font-> 

  Color = cellbuf [Col] [Row]. Color; 

  StringGrid1-> Canvas-> TextOut (Rect.Left +3, 

  Rect.Top +3, cellbuf [Col] [Row]. Msg); 

  ) 

  Fifth, the realization of software cover 

  — The prevalence of modern software design practices, in the completion of initialization procedures before the operation, the first call as a screen cover, usually 1 / 4 screen size, and show the the name of the software, the author, version and other information.    Use C + + Builder features such method is very simple: Since the definition of a form â‘  TSplashForm category, set to be "transparent window", that is, BorderIcons all options are under a false home, BorderStyle = bsNone, FormStyle = fsStayOnTop, Position = poScreenCenter; â‘¡ TSplashForm form in place a TPanel (equivalent to the graphics frame); â‘¢ TPanel place in a TImage controls, redeployment of the necessary graphics; â‘£ WinMain function of the slightly modified by adding the following code can be shown.    Needs to be pointed out is that this code by function FindWindow, search memory whether there is a window entitled "Demo" applications exist, if any, has withdrawn from the process operation.    This function can prevent the recurrence of operational procedures.    In some cases this design is essential. 

  WINAPIWinMain (HINSTANCE, HINSTANCE, LPSTR, int) 

  ( 

  Try 

  ( 

  If (FindWindow (NULL, "Demo")! = 0) 

  ( 

  Application-> MessageBox 

  ( "Procedures have been running!", "Warning", MB_ICONSTOP); 

  Return0; 

  ) 

  TSplashForm * newTSplashForm splash = (Application); 

  Splash-> Show (); 

  Splash-> Update (); 

  Application-> Initialize (); 

  Application-> CreateForm (__classid (TForm1), & Form1); 

  Splash-> Close (); 

  Deletesplash; 

  Application-> Run (); 

  ) 

  Catch (Exception & exception) 

  ( 

  Application-> ShowException (& exception); 

  ) 

  Return0; 

  ) 

  6. DBF how permanent removal of the records had been deleted 

  With table-> Delete () to delete the DBF records, and not really from the DBF database was deleted, but only cook a delete mark.    How to achieve similar dBase Pack in order function?    See the code below.    Table-> Close (); 

  For (;;) 

  Try 

  ( 

  Table-> Exclusive = true; 

  Table-> Open (); 

  Break; 

  ) 

  Catch (…) 

  ( 

  ) 

  If (DbiPackTable (table-> DBHandle, table-> 

  Handle, NULL, szDBASE, true)! = DBIERR_NONE) 

  Application-> MessageBox ( "can not delete records." 

  "Errors" 

MB_ICONSTOP);

  7, I / O port of achieving literacy 

  Attentive readers will find that the C + + Builder no longer support such as inportb (), outportb () for a Class I / O ports read and write command.    Precise, in the Windows environment, BorlandC + + supports only 16 applications for port operators, 32 applications no longer support the operation of the port, and C + + Builder developed by the procedure is 32.    I personally think that this is a C + + Builder designers failed.    Because PC machine, I / O address space and memory address space has always been separate.    Look at Delphi, not to achieve through the Port array of I / O ports visit?    Engage in it is not clear why the C + + Builder did not provide a similar mechanism?    Below these function is the author of Amoy down from the Internet, after verification, in Windows95 environment, it can be realized on the I / O port of literacy.    Readers can learn from the use. 

  Voidoutportb (unsignedshort 

  Intport, unsignedcharvalue) 

  ( 

  / / Movedx, * (& port); 

  __emit__ (0×8b, 0×95, & port); 

  / / Moval, * (& value); 

  __emit__ (0×8a, 0×85, & value); 

  / / Outdx, al; 

  __emit__ (0×66, 0xee); 

  ) 

  Voidoutportw (unsignedshort 

  Intport, unsignedshortintvalue) 

  ( 

  / / Movedx, * (& port); 

  __emit__ (0×8b, 0×95, & port); 

  / / Movax, * (& value); 

  __emit__ (0×66, 0×8b, 0×85, & value); 

  / / Outdx, ax; 

  __emit__ (0xef); 

  ) 

  Unsignedcharinportb (unsignedshortintport) 

  ( 

  Unsignedcharvalue; 

  / / Movedx, * (& port); 

  __emit__ (0×8b, 0×95, & port); 

  / / Inal, dx; 

  __emit__ (0×66, 0xec); 

  / / Mov * (& value), al; 

  __emit__ (0×88, 0×85, & value); 

  Returnvalue; 

  ) 

  Unsignedshortintinportw (unsignedshortintport) 

  ( 

  Unsignedshortintvalue; 

  / / Movedx, * (& port); 

  __emit__ (0×8b, 0×95, & port); 

  / / Inax, dx 

  __emit__ (0xed); 

  / / Mov * (& value), the ax 

  __emit__ (0×66, 0×89, 0×85, & value); 

  Returnvalue; 

  ) 

  8, and software distribution 

  In Windows applications under development in general are relatively large, and procedures are often inseparable from the operation of the system a lot of unknown DLL files.    To generate that from the C + + Builder environment, the independent operation of the application, readers need to compiler for certain settings.    Method: Home Project / Option / Packages / Runwithruntimepackages to Disable, Home Project / Option / Linker / UsesdynamicRTL to Disable, recompile again, and it is generated EXE files can be divorced from C + + Builder environment running.    But if you use the procedures of the database, only the above-mentioned operation is not enough - because, you will need to install BDE (BorlandDatabaseEngineer).    BDE installation trouble comparison, the reader is the best C + + Builder3.0 InstallShieldExpress incidental to the production installation disk, and the BDE application package together.    If not, can also be used Delphi3.0 InstallShieldExpress incidental to the production.    InstallShield the use of the limited space, no longer introduced.    Conditional readers relevant information can be found online.    Posted on at 2:57 on July 11, 2004 PM 

Bookmark it: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • Sphinn
  • del.icio.us
  • Google
  • DotNetKicks
  • DZone
  • Furl
  • Netvouz

Tags:

Releated Articles


0 Comments to “C + + Builder experience in the use of (turn)”

No Comments. Send your comment.

Leave a Reply

You must be logged in to post a comment.