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