home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 2000 March / pcp161b.iso / full / delphi / DELPHI16 / TECHINFO / DELPHI / FAQS / DELSEC09.FAQ < prev    next >
Encoding:
Text File  |  1995-08-24  |  6.6 KB  |  175 lines

  1. SECTION 9 - Component Design.
  2.  
  3. This document contains information that is most often provided
  4. to users of this section.  There is a listing of common
  5. Technical Information Documents that can be downloaded from
  6. the libraries, and a listing of the most frequently asked
  7. questions and their answers.
  8.  
  9. Technical Information Documents related to Component Design:
  10.  
  11. TI2841  Delphi Consultants and Training Centers
  12.  
  13. None
  14.  
  15. Zip files related to Component Design:
  16.  
  17. TBD
  18.  
  19. Questions and answers:
  20.  
  21. Q: "Should I purchase the VCL source code?"
  22.  
  23. A: If you are interested in component design then positively,
  24.    absolutely, one hundred percent YES!  Having the VCL source code
  25.    allows you to examine the way that VCL components are created right
  26.    down to the private sections.  This can be very useful when trying
  27.    to create your own custom components.  You also have the ability to
  28.    step through the source code with the debugger.
  29.  
  30.  
  31. Q: "Okay, I purchased the VCL source code but where is the source code
  32.    for the tabbed controls (i.e. TTabbedNotebook etc)?"
  33.  
  34. A: The source code doesn't contain the source for the tabbed controls
  35.    because of legal reasons.  However, the interface source is provided
  36.    in the DELPHI\DOC directory with an INT extension.
  37.  
  38.    Note:  Registered owners of the Delphi RTL source code can request
  39.    the TTabSet and TTabbedNotebook source code from Borland Corporate
  40.    Affairs by contacting Karen Rogers via fax at (US) 408-431-4171.
  41.  
  42.  
  43. Q: "I am trying to create a custom component but I'm not sure which
  44.    class I should decend from."
  45.  
  46. A: The easiest way is to decend from an existing component that has most
  47.    of the characteristics you are looking for.  If you have to create a
  48.    custom component from "scratch" then use one of the classes listed
  49.    below.
  50.  
  51.    TComponent      - The base starting point for non-visual components.
  52.    TWinControl     - The base starting point for components that need to
  53.                      have window handles.
  54.    TGraphicControl - A good starting point for visual components that
  55.                      don't need the overhead of a window handle.  This
  56.                      class has a Paint method, that should be overridden,
  57.                      but no canvas.
  58.    TCustomControl  - The most common starting point for visual components.
  59.                      This class has a Window handle, common events and
  60.                      properties, and most importantly a canvas with a
  61.                      Paint() method.
  62.  
  63.  
  64. Q: "How do I override the default message handler for my Application?"
  65.  
  66. A: You create a dynamic method that is indexed to the message constant
  67.    that you want to override.  If you want to override the CM_DIALOGKEY
  68.    message you would declare the following procedure in the public
  69.    section of you class declaration:
  70.  
  71.    Procedure CMDialogKey(var Message: TCMDialogKey);message CM_DIALOGKEY;
  72.  
  73.    It is common practice to declare the procedure name the same as the
  74.    message name minus the underscore.  Your message handler would look
  75.    something like this:
  76.  
  77.    Procedure TForm1.CMDialogKey(var Message: TCMDialogKey);
  78.    begin
  79.      if CharCode = VK_TAB then begin
  80.        {Process the Alt+Tab key here}
  81.        result := 1;
  82.        exit;
  83.      end;
  84.      inherited;
  85.    end;
  86.  
  87.    Setting result to 1 stops further processing. The inherited
  88.    statement passes control to the parent handler. Be sure to
  89.    execute inherited for all the cases you don't want to handle.
  90.    Do not execute it for the ones you do handle.
  91.  
  92.  
  93. Q: "Where is the best place to open a splash screen on program
  94.    start up?"
  95.  
  96. A: The best place to open a splash screen is in the project source
  97.    file after the first FormCreate and before the Run  This is
  98.    accomplisged by creating a form on the fly and then displaying it
  99.    before the app is actual opened.
  100.  
  101.    program Project1;
  102.  
  103.    uses Forms,  Unit1 in 'UNIT1.PAS' {Form1}, Splash;
  104.  
  105.    {$R *.RES}
  106.    var
  107.      SplashScreen : TSplashScreen;  {in the Splash unit}
  108.    begin
  109.    Application.CreateForm(TForm1, Form1);
  110.    SplashScreen := TSplashScreen.Create(Application);
  111.    try
  112.      SplashScreen.Show;
  113.      {
  114.       do other CreatForms or anyother processing
  115.       before the app is to be opened
  116.      }
  117.      SplashScreen.Close;
  118.    finally               {Make sure the splash screen gets released}
  119.      SplashScreen.Free;
  120.    end;
  121.    Application.Run;
  122.    end.
  123.  
  124.  
  125. Q: "What is the order of event handlers when a form is created
  126.    and shown?"
  127.  
  128. A: When a form is created the event handlers are executed in the
  129.    following order:  OnCreate, OnShow, OnPaint, OnActivate, OnResize
  130.    and OnPaint again.
  131.  
  132.  
  133. Q: "Why can't my program find any of the resources that I put in a
  134.    .RES file if that .RES file is the same name as my form's unit name?"
  135.  
  136. A: If the name of an included .RES file is the same as the name
  137.    of a .DPR file Delphi wll overwrite it with it's own .RES file.
  138.  
  139.  
  140. Q: "I have derived a component from a TPanel.  In the constructor, I
  141.    look at the BevelWidth property; it is always 1 regardless of what
  142.    the user sets it to at design time.  Apparently the property is
  143.    updated with the design time value after my constructor fires.
  144.    When does this happen?  Where is a good place to trap this value
  145.    during initialization of the component?"
  146.  
  147. A: When components are read from a stream, each component is first
  148.    constructed, then its property values are read from the stream.  A
  149.    component's Loaded method is called after all streaming has finished.
  150.    You can override Loaded to do something with the component after its
  151.    state has been loaded from the stream.
  152.  
  153.  
  154. Q: "I am trying to publish an array property but I keep getting a #202
  155.    error telling me that the property cannot be published.  I thought
  156.    that a property that has a property editor can be published.
  157.  
  158. A: Check the online help under "published parts" to see what properties
  159.    and fields can be published.  To stream the data for non-standard
  160.    data types (which include array properties), override the component's
  161.    inherited DefineProperties method to register a property reader and
  162.    writer routine. See TStringList source for an example - it uses
  163.    DefineProperties to register reader and writer routines to handle
  164.    streaming the strings in its list.
  165.  
  166.  
  167. Q: "I am creating a component at run time but the default values that
  168.    I have declared don't seem to be working.  Why not?"
  169.  
  170. A: You need to make sure that you are setting the default values for
  171.    the properties in the Create constructor for the component.  The
  172.    "default" value for a property is not used when you create a
  173.    component at run time.
  174.  
  175.