home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 31 / CDASC_31_1996_juillet_aout.iso / vrac / del2faq.zip / ALLFAQ.ZIP / DELSEC05.FAQ < prev    next >
Text File  |  1996-02-07  |  40KB  |  961 lines

  1. SECTION 5 - Delphi VCL
  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. Fax-back Technical Information Documents related to VCL components:
  10. TechFax number: 800-822-4269
  11.  
  12.   1171  Bug Report Form
  13.   2711  How to Circumvent the "Index not found" Exception
  14.   2776  List of Delphi books from Third-Party Publishers
  15.   2779  Delphi Client/Server and PowerBuilder Compared
  16.   2781  Step by Step Configuration of an ODBC Driver
  17.  
  18. Delphi FTP and WWW sites on Internet:
  19.  
  20.   ftp.borland.com
  21.   ftp.netcom.com   /pub/ic/ice-floe.
  22.  
  23.   http://www.Borland.com
  24.   http://www.cybernetics.net/users/bstowers/delphi-bugs.html
  25.   http://www.coriolis.com/coriolis/whatsnew/delphi.htm
  26.  
  27. Zip files related to VCL components:
  28.  
  29. MDI_BGRD.ZIP  Sample MDI application with a wallpaper background.
  30. CURREDIT.ZIP  Currency edit component.
  31.  
  32. Questions and answers:
  33.  
  34. ------------------------------------------------------------------------
  35.  
  36. Q: "How can VCL components be created on the fly at run-time?"
  37.  
  38. A: The following code will create a modal password form at runtime.
  39.    The TPasswordForm type is a TForm descendent class defined either
  40.    in the current unit or in a separate unit referenced by the current
  41.    unit's uses clause.
  42.  
  43.    with TPasswordForm.Create(Application) do
  44.    begin                               ( i.e TForm1, TPasswordForm etc. } 
  45.       ShowModal;                       { Display form as a modal window }
  46.       Free;                            { Free the form when it is closed }
  47.    end;      
  48.  
  49.    The following are the general steps to add a component to a form at 
  50.    run-time:  
  51.  
  52.    1. Declare an instance variable of the component type that you wish to
  53.       create {i.e. TButton }. Note: instance variables are used to point
  54.       to an actual instance of an object. They are not objects themselves.
  55.    2. Use the component's Create constructor to create an instance
  56.       of the component and assign the instance to the instance 
  57.       variable declared in step 1.  All components' Create constructors 
  58.       take a parameter - the component's owner.  Except in special 
  59.       circumstances, you should always pass the form as the owner 
  60.       parameter of the component's Create constructor.
  61.    3. Assign a parent to the component's Parent property (i.e. Form1,
  62.       Panel1, etc).  The Parent determines where the component will be 
  63.       displayed, and how the component's Top and Left coordinates are 
  64.       interpreted. To place a component in a groupbox, set the 
  65.       component's Parent property to the groupbox.  For a component
  66.       to be visible, it must have a parent to display itself within.
  67.    4. Set any other properties that are necessary  (i.e. Width, Height).
  68.    5. Finally, make the component appear on the form by setting the 
  69.       component's Visible property to True. 
  70.    6. If you created the component with an owner, you
  71.       don't need to do anything to free the component - it will be freed
  72.       when the owner is destroyed.  If you did not give the component an
  73.       owner when you created it, you are responsible for making sure
  74.       the component is freed when it is no longer needed.
  75.       The following demonstrates how to add a TButton component to the 
  76.       current form at run-time:  
  77.  
  78.    var
  79.      TempButton : TButton;  { This is only a pointer to a TButton }    
  80.    begin 
  81.      TempButton := TButton.Create(Self); { Self refers to the form }
  82.      TempButton.Parent := Self;          { Must assign the Parent } 
  83.      TempButton.Caption := 'Run-time';   { Assign properties now }
  84.      TempButton.Visible := True;         { Show to button }
  85.    end; 
  86.  
  87.    Since the button was created with an owner, it will be freed 
  88.    automatically when its owner, the form, is freed.     
  89.  
  90. ------------------------------------------------------------------------
  91.  
  92. Q: "How can the event handler of a popup menu item determine which 
  93.    component was right-clicked upon to activate that menu?
  94.  
  95. A: Use the PopupMenu.PopupComponent property 
  96.    to determine what control the menu was activated for.
  97.  
  98.    procedure TForm1.PopupItem1Click(Sender: TObject);
  99.    begin
  100.      Label1.Caption := PopupMenu1.PopupComponent.ClassName;
  101.    end;
  102.  
  103.    The form's ActiveControl property can also be used, however, 
  104.    the active control may not necessarily be the control that
  105.    caused the popup menu to appear. 
  106.  
  107. ------------------------------------------------------------------------
  108.  
  109. Q: "What are the capacity limits of the standard Delphi controls?"
  110.  
  111. A: Any component that uses a TList to store information has an upper
  112.    bound of 16368 items. For example, a TTabControl can contain up to
  113.    16368 tabs and the Delphi Component Palette can contain up to
  114.    16368 palette pages.
  115.  
  116.    Many of the Delphi standard components are wrappers around standard
  117.    Windows controls.  Windows 3.1 imposes its own limits on these 
  118.    components.  For example: a TComboBox or TListbox can hold up to
  119.    5440 items and TMemo or TEdit (and related components) can hold up 
  120.    to 32k of text.
  121.  
  122.    Windows 3.1 resource space imposes a limit of 570 pages in a 
  123.    TNoteBook component. (It's difficult to get more than 500 window 
  124.    handles in any Windows application.)
  125.  
  126.    Note 1: Exceeding these limits will raise exceptions or cause Windows
  127.    to behave strangely.
  128.  
  129.    Note 2: Many of the Windows-based capacity limits are much higher 
  130.    in the 16-bit WOW box of Windows NT and in Windows 95.  In future
  131.    32 bit releases of Delphi, virtually all of these limits will 
  132.    disappear.
  133.  
  134. ------------------------------------------------------------------------
  135.  
  136. Q: "How can I determine the Length in pixels of a string after a
  137.    specific font has been aplied to it?"
  138.  
  139. A: Use the Canvas methods TextHeight and TextWidth to
  140.    determine the text height and width of a string in
  141.    pixels.  Be sure to assign the font into the Canvas before
  142.    drawing or taking measurements.
  143.  
  144.    All visual components have a Canvas property, but
  145.    usually this property is protected so that only direct descendents
  146.    can draw on the Canvas.  Since you write much of your code
  147.    inside methods of a TForm descendent, you always have access to 
  148.    your form's inherited Canvas property.  The TPaintBox component
  149.    makes its Canvas property public so that you can draw on the
  150.    component from OnPaint event methods in the form.
  151.  
  152.    If a component doesn't have a Canvas property you can use the
  153.    following function to get the text width based on the font passed.
  154.  
  155.    function GetTextWidth(CanvasOwner: TForm; Text : String;
  156.                          TextFont :  TFont): Integer;
  157.    var
  158.      OldFont : TFont;
  159.    begin
  160.      OldFont := TFont.Create;
  161.      try
  162.        OldFont.Assign( CanvasOWner.Font );
  163.        CanvasOWner.Font.Assign( TextFont );
  164.        Result := CanvasOwner.Canvas.TextWidth(Text);
  165.        CanvasOWner.Font.Assign( OldFont );  
  166.      finally
  167.        OldFont.Free;
  168.      end;
  169.    end;
  170.  
  171. ------------------------------------------------------------------------
  172.  
  173. Q: "Why do some visual components like TPanel and TEdit not have a
  174.    Canvas property?"
  175.  
  176. A: All descendents of TCustomControl have a Canvas property, however,
  177.    most are protected to prevent 'outsiders' from drawing on the
  178.    component.  Descendents of a component can always access the 
  179.    protected properties they inherit from the component 
  180.    (such as Canvas), but users of the component cannot.
  181.  
  182.    type
  183.      TCanvasPanel = class(TPanel)
  184.      public
  185.        property Canvas;
  186.      end;
  187.  
  188.    If you want to draw on a component that doesn't have a public 
  189.    canvas property, consider using a different component that was 
  190.    intended for arbitrary drawing (TPaintBox), or layer components to 
  191.    achieve the desired result (client-align a TPaintBox inside a TPanel
  192.    to get a bevelled, drawable area).
  193.  
  194. ------------------------------------------------------------------------
  195.  
  196. Q: "How can I get a horizontal scrollbar on a list box?"
  197.  
  198. A: Send a LB_SetHorizontalExtent message to the listbox's window handle.
  199.    For example, the message could be sent in the form's OnCreate:
  200.  
  201.    procedure TForm1.FormCreate(Sender: TObject);
  202.    begin
  203.      SendMessage(Listbox1.Handle, LB_SetHorizontalExtent, 1000, Longint(0));
  204.    end;
  205.  
  206. ------------------------------------------------------------------------
  207.  
  208. Q: "Does Delphi have a component that supports serial communications?"
  209.  
  210. A: No. However, there are serial communications libraries (and soon 
  211.    Delphi components) for Delphi available from third party vendors
  212.    such as TurboPower, SaxComm, and and others.
  213.  
  214. ------------------------------------------------------------------------
  215.  
  216. Q: "How can the tab stops be set in a TMemo control?"
  217.  
  218. A: To change the tab stops for a multiline edit control
  219.    (i.e. a TMemo) send the EM_SetTabStops message to the
  220.    component.  The Tabs array indicates where the tab stops 
  221.    will be located.  Since the WParam parameter to 
  222.    SendMessage is 1, then all tab stops will be set to the 
  223.    value passed in the Tabs array.  Remember to set the
  224.    WantTabs property of TMemo to True to enable the tabs.
  225.  
  226.    procedure TForm1.FormCreate( Sender : TObject );
  227.    const
  228.      TabInc : LongInt = 10;
  229.    begin
  230.      SendMessage( Memo1.Handle, EM_SetTabStops, 1, Longint( @TabInc ) );
  231.    end;
  232.  
  233. ------------------------------------------------------------------------
  234.  
  235. Q: "Where is the best place to open a splash screen on program start up?"
  236.  
  237. A: The best place to open a splash screen is in the project source 
  238.    file after the first Application.FormCreate and before the
  239.    Application.Run.  This is accomplished by creating a form on
  240.    the fly and then displaying it before the application is actual
  241.    opened.
  242.  
  243.    program Project1;
  244.  
  245.    uses Forms, Unit1 in 'UNIT1.PAS' {Form1}, Splash;
  246.  
  247.    {$R *.RES}
  248.    var
  249.      SplashScreen : TSplashScreen;  {in the Splash unit}
  250.    begin
  251.      Application.CreateForm(TForm1, Form1);
  252.      SplashScreen := TSplashScreen.Create(Application);
  253.      try
  254.        SplashScreen.Show;
  255.        SplashScreen.Update; {Process any pending Windows paint messages}
  256.        {
  257.         do other CreatForms or any other processing before the
  258.         application is to be opened.  If the start up processing is
  259.         going to take a long time you may want to run
  260.         Application.ProcessMessages periodically to allow Windows
  261.         to respond to Windows messages.
  262.        }
  263.      finally               {Make sure the splash screen gets released}
  264.        SplashScreen.Free; 
  265.      end;   
  266.      Application.Run;
  267.    end.
  268.  
  269. ------------------------------------------------------------------------
  270.  
  271. Q: "Why does the OnExit event of a TEdit component not execute when 
  272.    the user clicks on a speed button?  Is there a way to make a 
  273.    an OnExit event execute when a speed button is pressed?"
  274.  
  275. A: A speed button never actually gets focus, so the active
  276.    control never loses its focus, consequently the active
  277.    control's OnExit event never occurs. 
  278.  
  279.    One way to execute the active control's OnExit event is to
  280.    explicitly call it in the OnClick event of the speedbutton. 
  281.    For example:
  282.  
  283.    procedure TForm1.SpeedButton1Click(Sender: TObject);
  284.    begin
  285.      If ActiveControl is TEdit then 
  286.         (ActiveControl as TEdit).OnExit(ActiveControl);
  287.    end;
  288.  
  289. ------------------------------------------------------------------------
  290.   
  291. Q: "When I open the child windows at run-time each one is 
  292.    positioned slightly down and to the right of the previous
  293.    window.  My problem is that if I then close some of the child 
  294.    windows and then open a new one, the new one is placed 
  295.    down and to the right of where the last child window was 
  296.    before I closed it, even though it is no longer there! 
  297.    Is this as designed?"  
  298.  
  299. A: That's how MDI windows works. VCL doesn't override Windows
  300.    default behavior in this situation.
  301.  
  302.    Untested suggestion: In the FormCreate procedure try 
  303.    setting the Top, Left, Width & Height properties to the values
  304.    that you require.  The MDI child form's FormCreate is called 
  305.    before the window is displayed.
  306.  
  307. ------------------------------------------------------------------------
  308.  
  309. Q: "Why can't my program find any of the resources that I put in a .RES 
  310.    file if that .RES file is the same name as my form's unit name?"
  311.  
  312. A: If the name of an included .RES file is the same as the name
  313.    of a .DPR file Delphi wll overwrite it with it's own .RES file.  
  314.    In addition, the project RES file is for the Delphi project
  315.    manager only; don't edit or add resources to this RES file.  
  316.  
  317. ------------------------------------------------------------------------
  318.  
  319. Q: "How can you do scrolling functions in a TForm component using 
  320.    keyboard commands?  For example, scrolling the form up and down 
  321.    with the PgUp and PgDn keys.  
  322.  
  323. A: Form scrolling is accomplished by modifying the VertScrollbar 
  324.    or HorzScrollbar Postion properties of the form.  The following
  325.    code demonstrates how to do this:
  326.  
  327.    procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  328.    Shift: TShiftState);
  329.    const
  330.      PageDelta = 10;
  331.    begin
  332.      With VertScrollbar do
  333.        if Key = VK_NEXT then  Position := Position+PageDelta
  334.        else if Key = VK_PRIOR then Position := Position-PageDelta;
  335.    end;
  336.  
  337.    Note: This may not work well if the active control uses PgUp & PgDn,
  338.    too, like a TMemo.
  339.  
  340. ------------------------------------------------------------------------
  341.  
  342. Q: "Is there a way to fill a TListbox or TMemo in one shot?"
  343.  
  344. A: To fill multiple lines of a TListbox or TMemo component the SetText
  345.    method can be used.  The null terminated string passed to the 
  346.    SetText method is a concatination of each line of text delimeted
  347.    by a carriage return character #13 in between.  For example, 
  348.    the follow statement:
  349.  
  350.    Listbox1.Items.SetText('aaaaa'#13'bbbbb'#13'ccccc')
  351.  
  352.    will display the following in a listbox window:
  353.  
  354.    aaaaa
  355.    bbbbb
  356.    ccccc
  357.  
  358.    Note: The preferred method of filling a listbox or memo is with the
  359.    Add method of their Items and Lines properties, respectfully.
  360.  
  361. ------------------------------------------------------------------------
  362.  
  363. Q: "Is it possible to create something like the Control Array in Visual
  364.    Basic?   For example, I want a group of buttons with a common event
  365.    handler whereby the event handler picks up an integer value for the
  366.    particular button. In Visual Basic this would be done via the
  367.    Control Array index."
  368.  
  369. A: One way do to this is to set the Tag field for each button to a
  370.    different number and then create a common OnClick event handler
  371.    that looks at the Sender's Tag field.  Assign the same OnClick
  372.    event handler to all the buttons in the group.  And then the
  373.    OnClick event handler would look something like this:
  374.  
  375.    procedure TForm1.Button1Click(Sender: TObject); var cap: string;
  376.    begin
  377.      case TButton(sender).Tag of
  378.        1: ShowMessage('1st Button Pressed');
  379.        2: ShowMessage('2nd Button Pressed');
  380.        3: ShowMessage('3rd Button Pressed');
  381.      end;
  382.    end;
  383.  
  384. ------------------------------------------------------------------------
  385.  
  386. Q: "How can a new component be added to a page of a
  387.    TTabbedNoteBook at run time?  How do I determine 
  388.    what the parent will be for the new component?"
  389.  
  390. A: To add a component to a TabbedNotebook page at run-time a
  391.    pointer to the desired page must be assigned to the new
  392.    component's Parent property before it can be shown.  The way to 
  393.    access all the pages of a TTabbedNotebook at run-time is with 
  394.    the Objects array property of the TabbedNotebook's Pages property.
  395.    In other words, the page components are stored as objects attached
  396.    to the page names in the Pages string list property.  The follow
  397.    demonstrates the creation of a button on the second page of
  398.    TabbedNotebook1:
  399.  
  400.    var 
  401.      NewButton : TButton;
  402.    begin
  403.      NewButton := TButton.Create(Self);
  404.      NewButton.Parent := TWinControl(TabbedNotebook1.Pages.Objects[1])
  405.      ...               
  406.      
  407.    This is how a TNotebook page would be used as a parent to a newly 
  408.    created component on that page: 
  409.     
  410.    NewButton.Parent := TWinControl(Notebook1.Pages.Objects[1])
  411.  
  412.    This is how a TTabSet tab page would be used as a parent to a
  413.    newly created component on that tab page: 
  414.     
  415.    NewButton.Parent := TWinControl(TabSet1.Tabs.Objects[1])
  416.  
  417. ------------------------------------------------------------------------
  418.  
  419. Q: "Are there any vertical ( side of the page ) tab components
  420.    available, commercial, shareware or freeware."
  421.  
  422. A: TurboPower's Orpheus product will support this. GO TURBOPOWER
  423.    for more information.
  424.  
  425. ------------------------------------------------------------------------
  426.  
  427. Q: "Is there an easy way to get CopyToClipboard, CutToClipboard etc. 
  428.    to know to use the TEdit that has focus?  
  429.  
  430. A: Simply check to see if the ActiveControl is of type TEdit and then 
  431.    do the desired cut, copy or paste operation. For example:
  432.  
  433.    if (ActiveControl is TEdit) then
  434.       TEdit(ActiveControl).CopyToClipboard;     
  435.  
  436. ------------------------------------------------------------------------
  437.  
  438. Q: "Does a TDBGrid component have an OnMouseDown, OnMouseUp and 
  439.    OnMouseMove events?"
  440.  
  441. A: The events are there, but they aren't published.  You could 
  442.    create a simple decendant of TDBGrid and publish them.
  443.  
  444. ------------------------------------------------------------------------
  445.  
  446. Q: "Does Delphi grab system resources when displaying and closing
  447.    modal dialogs?  For example, the following code decreases the
  448.    system resources every time it is used to show a modal dialog."
  449.  
  450.    ModalForm1 := TModalForm1.Create(Self);
  451.    ModalForm1.ShowModal;
  452.  
  453. A: Without an OnClose event handler that sets Action parameter to
  454.    caFree, your code is creating a new form with each call to
  455.    TModalForm1.Create(Self), but the previously created form is
  456.    never destroyed.  All previous instances of the "ModalForm1"
  457.    forms are floating around in Windows.
  458.  
  459.    The Free method of a form can also be used to free its resources.
  460.    This is demonstrated below:
  461.  
  462.    try
  463.      ModalForm1.ShowModal;
  464.      { other stuff here }
  465.    finally
  466.      ModalForm1.Free;
  467.    end;
  468.  
  469. ------------------------------------------------------------------------
  470.  
  471. Q: "What is the best way to create a radio button group and
  472.    place radio buttons on it?  It seems that you can create a
  473.    Radio Group then drop Radio Buttons on it or you can 
  474.    create the group and enter values into the Items properties
  475.    for the titles (captions) of the radio buttons and have
  476.    Delphi place them in the group?"      
  477.  
  478. A: If you're going to use a radio group, you need to create your
  479.    radio buttons using the Items string list.  Radio buttons
  480.    don't have to be in a group, which is why the plain radio 
  481.    button component is available.
  482.  
  483. ------------------------------------------------------------------------
  484.  
  485. Q: "Is there a way to make sure the window that is holding a form 
  486.    or an image component is byte-aligned?" 
  487.  
  488. A: Override the CreateParams method:
  489.  
  490.    procedure TMyForm.CreateParams(var Params:TCreateParams);
  491.    begin
  492.      inherited CreateParams(Params);
  493.      Style := Style or CS_BYTEALIGNWINDOW;
  494.    end; 
  495.  
  496.    Note: Byte alignment is less of a big deal than the Windows docs
  497.    imply.  It is only significant on monochrome, EGA, and 16 color
  498.    VGA video modes. All higher video modes are always byte-aligned.
  499.  
  500. ------------------------------------------------------------------------
  501.  
  502. Q: What is the order of event handlers when a form is created 
  503.    and shown?
  504.  
  505. A: When a form is created the event handlers are executed in the
  506.    following order:  OnCreate, OnShow, OnPaint, OnActivate, OnResize
  507.    and OnPaint again. 
  508.  
  509. ------------------------------------------------------------------------
  510.  
  511. Q: "Why does the error 'Cannot change Visible in OnShow or OnHide'
  512.    occur when the FormStyle property of a form is changed in the
  513.    OnActivate event? 
  514.  
  515. A: The FormStyle property defines how the window gets created and 
  516.    is usually set in the OnCreate event, however, it can changed 
  517.    after the window handle has been created, just not during the
  518.    OnActivate, OnShow or OnHide events.  The issue here is with the
  519.    mode that the system is in during OnShow and OnHide events.
  520.  
  521. ------------------------------------------------------------------------
  522.  
  523. Q: "How can I make components look sunken and raised?
  524.  
  525. A: To make a component look raised or lowered place it on  
  526.    a TBevel or TPanel component which both have properties to
  527.    raise or lower their frames.
  528.  
  529. ------------------------------------------------------------------------
  530.  
  531. Q: Where is the source code for the tabbed controls (i.e.
  532.    TTabbedNotebook)?
  533.  
  534. A: The source code files shipped with Delphi does not contain the
  535.    source for the tabbed controls because of legal reasons. However,
  536.    the interface source for the tabbed controls is provided
  537.    in the DELPHI\DOC directory with an INT extension.
  538.     
  539.    Note: Registered owners of the Delphi RTL source code can request
  540.    the TTabSet and TTabbedNotebook source code from Borland Corporate
  541.    Affairs.  Instructions are in the RTL source readme.
  542.  
  543. ------------------------------------------------------------------------
  544.  
  545. Q: "What is the memo field size in Delphi?"
  546.  
  547. A: Microsoft's edit control that is built-in to Windows and used 
  548.    by Delphi's TEdit and TMemo wrapper classes has a maximum 
  549.    capacity of 32k.  The Delphi wrapper classes do some special
  550.    things  to allow every edit and memo control on a form to
  551.    contain up to 32k each.  Normally all edit controls in an
  552.    application would be limited to 32k collectively.
  553.  
  554. ------------------------------------------------------------------------
  555.  
  556. Q: "How can I make a field in the TGrid component not show up?"
  557.  
  558. A: This can be accomplished by either removing the field entirely 
  559.    from the Fields Editor's field list or by setting the Visible
  560.    property of the field to False. 
  561.  
  562. ------------------------------------------------------------------------
  563.  
  564. Q: "Is there a way to put a wallpaper background on an MDI 
  565.    application?"
  566.  
  567. A: There is a sample application that demostrates this in the VCL
  568.    section (5) of the Delphi forum under the name of MDI_BGRD.ZIP.  
  569.  
  570. ------------------------------------------------------------------------
  571.  
  572. Q: "Does Delphi have a currency/money component?"
  573.  
  574. A: No, bu there is a currency edit component in the VCL section of the
  575.    Delphi forum under the name of CURREDIT.ZIP.  
  576.  
  577. ------------------------------------------------------------------------
  578.  
  579. Q: "Where can I find out about VBX datatypes (i.e. TBasicString) and
  580.    the functions to manipulate these datatypes?"
  581.       
  582. A: First off, all VBX related datatypes and functions are in the 
  583.    VBXCtrls unit which is Borland propriatary unit.  Delphi does,
  584.    however, provide the interface section of this unit is in the
  585.    \DELPHI\DOC directory under the name of VBXCTRLS.INT.  This is the
  586.    only real source of information on the contents of the VBXCtrls unit.
  587.  
  588. ------------------------------------------------------------------------
  589.  
  590. Q: "What issues do I need to be aware of when developing applications
  591.    that will be ran on different screen resolutions (form scaling)?"
  592.  
  593. A: The following are issue to bear in mind when scaling Delphi
  594.    applications (forms) on different screen resolutions?
  595.  
  596.   * Decide early on in the form design stage whether you're going to 
  597.     allow the form to be scaled or not.  The advantage of not scaling is
  598.     that nothing changes at runtime.  The disadvantage of not scaling is
  599.     that nothing changes at runtime (your form may be far too small or
  600.     too large to read on some systems if it is not scaled).
  601.  
  602.   * If you're NOT going to scale the form, set Scaled to False.
  603.  
  604.   * Otherwise, set the Form's Scaled property to True.
  605.  
  606.   * Set AutoScroll to False.  AutoScroll = True means 'don't change the
  607.     form's frame size at runtime' which doesn't look good when the 
  608.     form's contents do change size.
  609.  
  610.   * Set the form's font to a scaleable TrueType font, like Arial.  
  611.     MS San Serif is an ok alternate, but remember that it is still a 
  612.     bitmapped font.  Only Arial will give you a font within a pixel of
  613.     the desired height.  NOTE: If the font used in an application is not
  614.     installed on the target computer, then Windows will select an 
  615.     alternative font within the same font family to use instead. 
  616.     This font may not match the same size of the original font any may
  617.     cause problems.
  618.  
  619.   * Set the form's Position property to something other than poDesigned. 
  620.     poDesigned leaves the form where you left it at design time, which
  621.     for me always winds up way off to the left on my 1280x1024 screen - 
  622.     and completely off the 640x480 screen.
  623.  
  624.   * Don't crowd controls on the form - leave at least 4 pixels between 
  625.     controls, so that a one pixel change in border locations (due to 
  626.     scaling) won't show up as ugly overlapping controls.
  627.  
  628.   * For single line labels that are alLeft or alRight aligned, set
  629.     AutoSize to True.  Otherwise, set AutoSize to False.
  630.  
  631.   * Make sure there is enough blank space in a label component to allow
  632.     for font width changes - a blank space that is 25% of the length of
  633.     the current string display length is a little too much, but safe.
  634.     (You'll need at least 30% expansion space for string labels if you 
  635.     plan to translate your app into other languages) If AutoSize is 
  636.     False, make sure you actually set the label width appropriately. 
  637.     If AutoSize is True, make sure there is enough room for the label 
  638.     to grow on its own.
  639.  
  640.   * In multi-line, word-wrapped labels, leave at least one line of
  641.     blank space at the bottom.  You'll need this to catch the overflow
  642.     when the text wraps differently when the font width changes with
  643.     scaling. Don't assume that because you're using large fonts, you
  644.     don't have to allow for text overflow - somebody else's large 
  645.     fonts may be larger than yours!
  646.  
  647.   * Be careful about opening a project in the IDE at different
  648.     resolutions.  The form's PixelsPerInch property will be modified
  649.     as soon as the form is opened, and will be saved to the DFM if
  650.     you save the project. It's best to test the app by running it
  651.     standalone, and edit the form at only one resolution. Editing
  652.     at varying resolutions and font sizes invites component drift 
  653.     and sizing problems.
  654.  
  655.   * Speaking of component drift, don't rescale a form multiple times,
  656.     at design time or a runtime.  Each rescaling introduces roundoff
  657.     errors which accumulate very quickly since coordinates are 
  658.     strictly integral.  As fractional amounts are truncated off
  659.     control's origins and sizes with each successive rescaling, 
  660.     the controls will appear to creep northwest and get smaller.
  661.     If you want to allow your users to rescale the form any number 
  662.     of times, start with a freshly loaded/created form before each 
  663.     scaling, so that scaling errors do not accumulate.
  664.  
  665.   * Don't change the PixelsPerInch property of the form, period.
  666.  
  667.   * In general, it is not necessary to design forms at any particular
  668.     resolution, but it is crucial that you review their appearance at
  669.     640x480 with small fonts and large, and at a high-resolution with
  670.     small fonts and large before releasing your app.  This should be 
  671.     part of your regular system compatibility testing checklist.
  672.  
  673.   * Pay close attention to any components that are essentially 
  674.     single-line TMemos - things like TDBLookupCombo.  The Windows 
  675.     multi-line edit control always shows only whole lines of text - 
  676.     if the control is too short for its font, a TMemo will show 
  677.     nothing at all (a TEdit will show clipped text). For such 
  678.     components, it's better to make them a few pixels too large than
  679.     to be one pixel too small and show not text at all.
  680.  
  681.   * Keep in mind that all scaling is proportional to the difference 
  682.     in the font height between runtime and design time, NOT the pixel
  683.     resolution or screen size.  Remember also that the origins of your
  684.     controls will be changed when the form is scaled - you can't very 
  685.     well make components bigger without also moving them over a bit.
  686.  
  687. ------------------------------------------------------------------------
  688.  
  689. Q: "How can I get rid of the ReportSmith about box splash screen
  690.    when I run a report."
  691.  
  692. A: Add the following line in [RS_RunTime] section of the 
  693.    RS_RUN.INI file to not have the ReportSmith about box appear
  694.    when a report is ran.
  695.  
  696.    ShowAboutBox=0
  697.  
  698. ------------------------------------------------------------------------
  699.  
  700. Q: "How do you make a moveable multi-split window?"
  701.  
  702. A: The following steps and code demonstrate how to make a
  703.    simple splitter window.
  704.  
  705.    1) Put a memo on a form and set its Align property to alTop. 
  706.    2) Place a panel on the form and set its Align property to alTop.
  707.    3) Set the panel's Height property to 6 or 7. 
  708.    4) Set the panel's DragMode property to dmAutomatic.
  709.    5) Set the panel's DragCursor property to crVSplit.
  710.    6) Set the panel's Cursor property to crVSplit.
  711.    7) Add another memo on the form and set its Align property to
  712.       alClient. 
  713.    8) Now select both memos and the panel, and connect them all
  714.       to this OnDragOver handler:
  715.  
  716.     procedure TForm1.Memo1DragOver(Sender, Source: TObject; X, 
  717.       Y: Integer; State: TDragState; var Accept: Boolean);
  718.     begin
  719.       Accept := False;
  720.       if Source = Panel1 then begin
  721.          Accept := True;
  722.          Memo1.Height := Y + (Sender as TControl).Top;
  723.       end;
  724.     end;
  725.  
  726. ------------------------------------------------------------------------
  727.  
  728. Q: "How can I determine the current row and column position of 
  729.    the caret in a TMemo component?
  730.  
  731. A: You can use the Windows API messages EM_LINEFROMCHAR and
  732.    EM_LINEINDEX to determine the current line and offset within that
  733.    line (starting from SelStart).    
  734.  
  735.    var
  736.      LineNum: longint;
  737.      CharsBeforeLine: longint;
  738.    begin
  739.      LineNum := SendMessage(Memo1.Handle, EM_LINEFROMCHAR, Memo1.SelStart,0);
  740.      CharsBeforeLine := SendMessage(Memo1.Handle, EM_LINEINDEX, LineNum, 0);
  741.      Label1.Caption := 'Line ' + IntToStr(LineNum +1) 
  742.      Lebel2.Caption := 'Position ' + IntToStr((Memo1.SelStart - CharsBeforeLine) + 1);
  743.    end;
  744.  
  745. ------------------------------------------------------------------------
  746.  
  747. Q: How can I get the pixels per inch of the printer? 
  748.  
  749. A: If you want the value in pixels you can use the API function
  750.    GetDeviceCaps().  For example:
  751.  
  752.    VertPixelsPerInch := GetDeviceCaps(Printer.Handle, LogPixelsX);
  753.    HorzPixelsPerInch := GetDeviceCaps(Printer.Handle, LogPixelsY);
  754.  
  755. ------------------------------------------------------------------------
  756.  
  757. Q: "Is there a way to store an integer value along with a string
  758.    value in a TString list object or property?"
  759.  
  760. A: Yes, but it requires some type conversions.  The TString 
  761.    component has an Objects array along with the string array 
  762.    that can be utilized for the purpose of storing integer datA:
  763.    The data type that the Objects array holds is TObject.  In 
  764.    essence it holds a 4 byte pointer value.  So to put an integer
  765.    value in it you would need to type cast that value.  For
  766.    example, the following is adding a string and an integer
  767.    value of 100 to an items property (TString object) of a
  768.    Listbox:
  769.  
  770.    Listbox1.Items.AddObject('Text string', TObject(100)); 
  771.  
  772.    To get the value out do the following:
  773.  
  774.    Result := LongInt( Listbox1.Items.Objects[0] ); 
  775.  
  776.    This assumes that Result is of type Longint and that the 
  777.    value that were after is at index position 0.
  778.  
  779.    Note:  Though this works it is never wise to rely on the
  780.    internal workings of an object.  This is trick code and 
  781.    should be well commented.
  782.  
  783.    If you want to keep track of more than one value then a new 
  784.    class can be derived from the TObject base class to hold 
  785.    these values.
  786.   
  787.    type
  788.      ManyValues = class(TObject) 
  789.        Value1 : Integer;
  790.        Value2 : Integer;
  791.      end;
  792.     ...
  793.  
  794. ------------------------------------------------------------------------
  795.  
  796. Q:  Is it possible to access components by their name property (i.e. 
  797.     'SpeedButton' + IntToStr(i) )
  798.  
  799. A: Yes it's possible.  The following example uses the FindComponent
  800.    method of Form1 to disable the first 10 SpeedButtons by name. 
  801.  
  802.    for I := 1 to 10 do
  803.      with Form1.FindComponent('SpeedButton' + IntToStr(i)) as TSpeedButton do
  804.         Enabled := False;
  805.  
  806.  
  807. ------------------------------------------------------------------------
  808.  
  809. Q: How do you create a 'modal' form in an MDI application?  When my 
  810.    application calls the ShowModal method I get an error "Can't Show Modal
  811.    when Visible is set true".  When I try to set Visible to False, I get 
  812.    the error, can't set Visible to False on an MDI Child.
  813.  
  814. A: Normally, the first form of a project (the main form) is created with
  815.    its Visible property set to True, and all of the other forms are created
  816.    with their Visible properties set to False. An MDI child form, on the 
  817.    other hand, can't be invisible, so its Visible property is set to True.
  818.    When you change its form style back to fsNormal, the Visible property 
  819.    stays True, so you need to set it to False manually.
  820.  
  821. ------------------------------------------------------------------------
  822.  
  823. Q: Is there a way to change the default font size for components when
  824.    they are placed on a form?
  825.  
  826. A: Just add a form with it's Font property set to your desired font to the
  827.    gallery. Since, by default, components reflect the parent's font any
  828.    components you add to your form will take on that font. In addition,
  829.    you can set your new form as the Default Main Form and Default New
  830.    Form from the gallery (Options | Gallery...).
  831.  
  832. ------------------------------------------------------------------------
  833.  
  834. Q: How can I determine the directory that my program was executed
  835.    from?
  836.  
  837. A: The following function extracts the path from the ExeName
  838.    property of the global Application object.
  839.  
  840.    function GetExePath : String;
  841.    var
  842.      LastBackSlashPos, Index : Integer;
  843.    begin
  844.      Result := Application.ExeName; 
  845.      for Index := 1 to length(Result) do
  846.        if Result[Index] = '\' then
  847.           LastBackSlashPos := Index;
  848.      { subtract 1 so that the last backslash is not included }
  849.      Result[0] := chr(LastBackSlashPos - 1);
  850.    end;
  851.  
  852. ------------------------------------------------------------------------
  853.  
  854. Q: How can I change Font.Style back to normal after calling 
  855.    Canvas.Font.Style := [fsBold]?  The online help shows 
  856.    ([fsBold],[fsItalic] etc] but does not mention normal style.
  857.  
  858. A:  You simply specify an empty set for no style at all:
  859.  
  860.     Canvas.Font.Style := []; 
  861.  
  862.     or, you might just want to exclude the fsBold style like this:
  863.  
  864.     Canvas.Font.Style := Canvas.Font.Style - [fsBold];
  865.  
  866. ------------------------------------------------------------------------
  867.  
  868. Q: How can I get some actions to happen after a form is showing 
  869.    normally?  It seems that all the form events (OnCreate, OnPaint,
  870.    etc.) happen before the form is show.
  871.  
  872. A: You can add "Visible := True" inside OnCreate event, and then
  873.    do whatever you wish.
  874.  
  875. ------------------------------------------------------------------------
  876.  
  877. Q:  How much GDI resource does each built-in components use?
  878.  
  879. A: The TGraphicControl descendants like TLabel and TBevel don't use
  880.    free system resources at all. On the other hand, TWinControl descendants 
  881.    like TEdit and TPanel do.  Also each radio button in a TRadioGroup is a
  882.    window, i.e. has a window handle.
  883.  
  884. ------------------------------------------------------------------------
  885.  
  886. Q: Why does a TTabbedNotebook use so much of the system resources
  887.    when only one page is showing at a time?
  888.  
  889. A: Even though only one page is showing at a time each pages'
  890.    components have already been created thus taking resources.
  891.    One solution to this is instead of using a notebook you use 
  892.    a separate form for each page and when the user clicks on a
  893.    tab, the existing page is destroyed and the new one created.
  894.    The basic steps to set this is is as follows:
  895.  
  896.    First, each child form needs its creation parameters setup 
  897.    in a certain way:
  898.  
  899.    ...
  900.    private
  901.      { Private declarations }
  902.      PROCEDURE CreateParams(VAR Params: TCreateParams); override;
  903.    ...
  904.    procedure TForm2.CreateParams(VAR Params: TCreateParams);
  905.    begin
  906.      Inherited  CreateParams(Params);
  907.      with Params do begin
  908.        WndParent := Application.MainForm.Handle;
  909.        Style := (Style OR WS_CHILD) AND NOT (WS_POPUP);
  910.      end;
  911.    end;
  912.  
  913.     The child form's BorderStyle must be set to bsNone. In the
  914.     main form, create a private data field Child of type TForm. 
  915.     Initialize it in the OnActivate event, NOT OnCreate. And each
  916.     time the tab is clicked to change "pages", free the existing 
  917.     Child and initialize a new one of the desired type. E.g. in 
  918.     OnActivate do:
  919.  
  920.      Child := TForm2.Create(Self);
  921.      with Child do begin
  922.        Parent := Self;
  923.        Align := alClient;
  924.        Visible := True;
  925.      end;
  926.  
  927.     When you create a child page due to a tab change, do it in the
  928.     same way just shown. Of course you'll need to use the main form
  929.     to store any data about the state of the controls in a given
  930.     child window, because the data will go bye-bye when the child
  931.     is freed.
  932.  
  933. ------------------------------------------------------------------------
  934.  
  935. Q. How do you deselect one or more items in a listbox or combobox?
  936.  
  937. A. Listbox1.ItemIndex := -1;
  938.  
  939. ------------------------------------------------------------------------
  940.  
  941. Q. Why is it that when I call a dialog window such as MessageBox()
  942.    from within an event handler such as OnExit that the blinking 
  943.    cursor (the caret) disappears upon closing the dialog?
  944.  
  945. A. This is a Windows behavior.  Forcing an additional focus change
  946.    (e.g., with ShowMessage) during an event associated with a focus 
  947.    change (e.g., OnExit) will cause Windows to become confused.  It is
  948.    Windows that is controlling the focus change, and it is Windows that
  949.    becomes confused when you force a focus change in the middle of that
  950.    process.
  951.  
  952. ------------------------------------------------------------------------
  953.  
  954. Q.  Why do I get the exception 'EInvalidOperation: Cannot make a visalbe 
  955.     window modal' when I try to open a form with Showmodal?  The form is
  956.     not open yet.
  957.  
  958. A.  Make sure the form's Visible property is not being set to Ture at 
  959.     design-time or run-time.
  960.  
  961. ------------------------------------------------------------------------