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

  1. SECTION 7 - Object Pascal
  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 the
  6. libraries, and a listing of the most frequently asked
  7. questions and their answers.
  8.  
  9.  
  10. TI1171  Bug Report Form
  11.  
  12.  
  13. Index Of Questions
  14. ------------------
  15.  
  16. 1) I am using a form from the gallery and I am getting an 'unknown identifier' 
  17.    error when I compile.  What is wrong?
  18. 2) How can I do standard output with writeln?
  19. 3) How to I cast a floating point number (e.g. real) to an integer?
  20. 4) How do I make it so that when the user hits <enter>, it goes to the next
  21.    object as though he had hit the tab key? (Note: This will not work within 
  22.    a DBGrid, since the next field is not a separate object.)
  23. 5) In a DBGrid, how do I Tab to the next field when the Enter Key is pressed?
  24. 6) How do I process command line parameters in a Delphi app?
  25. 7) How do you select a specific field on a TDBGrid to get focus?
  26. 8) I have a paradox table that uses a password.  How do I make it so that the 
  27.    form that uses the table comes up without prompting the user for the 
  28.    password?
  29. 9) How do I design a form so that the display is the same no matter what the 
  30.    resolution is?
  31. 10) How do I do date math on calculated fields?
  32. 11) Where is the exponent function?
  33. 12) How do I keep the form in icon form when I run it?  
  34. 13) I have a form that is a sort of template.  I want to be able to call the
  35.     same form several times (with different data displayed).  How do I use 
  36.     one form several times?
  37. 14) How can the component that was right clicked be determined while in an 
  38.     event handler of a popup MenuItem?
  39. 15) How can I capture windows messages and process them before my 
  40.     application.run line is executed?
  41. 16) How do I use a case statement to determine which object calls the procedure?
  42. 17) How can you do scrolling functions in a TForm component using keyboard 
  43.     commands?  For example, scrolling up and down when a  PgUp or PgDown is 
  44.     pressed.  Is there some simple way to do this or does it have to be 
  45.     programmed by capturing the keystrokes and manually responding to them?
  46. 18) How do I transfer the text in a TMemo component on a form to a TMemofield 
  47.     in a Paradox table?
  48. 19) How do I make an Fixed Length ASCII text table from a table?
  49. 20) How do I set a format for a data field?
  50. 21) How do I format a number to place commas as a thousanth's separator?
  51. 22) I have a CPU intensive function.  I want to be able to check to see if the 
  52.     user wants to cancel.  How do I do that?
  53. 23) How do you extract the high or low order byte from a word?  How do you 
  54.     insert it?  
  55. 24) I have an OBJ file that has several assembler routines compiled into it.
  56.     I wouldn't want to have to rewrite them.  Is there a way to use them in
  57.     a Delphi app?
  58. 26) If a component doesn't handle the windows messages that I need it to 
  59.     handle, do I have to write my own version that passes the messages that 
  60.     I need, or is there way to tap (from a TForm or else where) into the 
  61.     message loop, and grap what I need?
  62. 27) Borland decided that accessing environment variables from Windows 
  63.     Programs is a Bad Thing.  Why do they force you to use the "obsolete" 
  64.     WinDos unit?
  65. 28) How would I write a basic screen saver (like, blank the screen) using Delphi?
  66. 29) How can I determine the Length in pixels of a string after a specific font has 
  67.     been aplied to it?
  68. 30) Where is the best place to open a splash screen on program start up?
  69. 31) How do I call a function from a DLL?
  70. 32) What is a Callback function, and how do I create one?
  71.  
  72.  
  73. Questions and Answers
  74. ---------------------
  75.  
  76. 1) Q:  I am using a form from the gallery and I am getting an 'unknown 
  77.        identifier' error when I compile.  What is wrong?
  78.  
  79.    A:  If you change the name of some item that has code associated with it, that 
  80.        code will not be changed by Delphi.  Delphi does not go through your code 
  81.        and second guess your intent.  The code that you may assume is generated  
  82.        by Delphi is actually programmed into the form by the designer of that    
  83.        form. Just go through the code and make the modifications.
  84.  
  85.  
  86. 2) Q:  How can I do standard output with writeln?
  87.  
  88.    A:  Include WinCRT in your uses statement.
  89.  
  90.  
  91. 3) Q:  How to I cast a floating point number (e.g. real) to an integer?
  92.  
  93.    A:  There are a couple of methods.
  94.  
  95.            var
  96.       i: integer;
  97.       r: real;
  98.  
  99.     begin
  100.       r := 34.56;
  101.       i := trunc(r);  {i = 34}  {First Method}
  102.       i := round(r);  {i = 35}  {Second Method}
  103.     end;
  104.  
  105.  
  106. 4) Q:  How do I make it so that when the user hits <enter>, it goes to the next
  107.        object as though he had hit the tab key? (Note: This will not work within 
  108.        a DBGrid, since the next field is not a separate object.)
  109.  
  110.    A:  You need to trap the keystroke and set up your own response to it.  Try
  111.        this:
  112.  
  113.     procedure TMainForm.FormCreate(Sender: TObject);
  114.     begin
  115.       keyPreview := true; {To turn the event "ON".}
  116.     end;
  117.  
  118.     procedure TMainForm.FormKeyPress(Sender: TObject; var Key: Char);
  119.     begin
  120.       if Key = #13 then
  121.       begin
  122.         Key := #0;
  123.         PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);
  124.       end;
  125.     end;
  126.  
  127. 5) Q: In a DBGrid, how do I Tab to the next field when the Enter Key is pressed?
  128.  
  129.    A: The action of the tab key is acted upon after the OnKeyDown event but the
  130.       Enter key is acted on in the OnKeyPress.  Therefore, the Enter key has to  
  131.       be accounted for in both areas for the desired effect to occur. Try this:
  132.  
  133.     procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift:
  134.      TShiftState);
  135.     begin
  136.         if Key = VK_RETURN then Key = VK_TAB;
  137.     end;
  138.  
  139.     procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);
  140.     begin
  141.         if Key = #13 then Key := #9;
  142.     end;
  143.  
  144.  
  145. 6) Q:  How do I process command line parameters in a Delphi app?
  146.  
  147.    A:  Use the ParamCount and ParamString methods.
  148.  
  149.  
  150. 7) Q:  How do you select a specific field on a TDBGrid to get focus?
  151.  
  152.    A:  Using this code:
  153.  
  154.     DBGrid1.SelectedField := Table1SomeField;
  155.     DBGrid1.SetFocus;
  156.  
  157.  
  158. 8) Q:  I have a paradox table that uses a password.  How do I make it so that the 
  159.        form that uses the table comes up without prompting the user for the 
  160.        password?  
  161.  
  162.    A:  The table component's ACTIVE property must be set to FALSE.  Then, put 
  163.        this code on the form's create event:
  164.  
  165.     session.AddPassword('My secret password');
  166.     table1.active := true; 
  167.  
  168.  
  169. 9) Q:  How do I design a form so that the display is the same no matter what the
  170.        resolution is?  
  171.  
  172.    A:  Here is some code to show how it is done:
  173.  
  174.     const
  175.       ScreenHeight: real = 800; {I designed my form in 800x600 mode.}
  176.       ScreenWidth: real = 600;
  177.  
  178.     procedure TForm1.FormCreate(Sender: TObject);
  179.     var
  180.       x, y: LongInt; {Integers will not not a large enough value.}
  181.  
  182.     begin
  183.       form1.scaled := true;
  184.       x := getSystemMetrics(SM_CXSCREEN);
  185.       y := getSystemMetrics(SM_CYSCREEN);
  186.       if (x <> ScreenHeight) or (y <> ScreenWidth) then
  187.         begin
  188.           form1.height := form1.height * x DIV ScreenHeight;
  189.           form1.width := form1.width * y DIV ScreenWidth;
  190.           scaleBy(x, ScreenHeight);
  191.         end;
  192.     end;
  193.  
  194.        Note: you may want to add code that will change the font sizes 
  195.        proportionally.
  196.  
  197.  
  198. 10) Q:  How do I do date math on calculated fields?
  199.  
  200.     A:  When doing date math on calculated fields, it is important to ensure that 
  201.         all values being used are properly matched as to type.  The double method 
  202.         (not in the docs) casts the value to a useable type.
  203.  
  204.  
  205.         In the following method, d1, and d2 (part of table1) can be of either    
  206.         date or dateTime type and d3 is an integer field.
  207.  
  208.     procedure TForm1.Table1CalcFields(DataSet: TDataset);
  209.     var
  210.       t1, t2: tDateTime;
  211.     begin
  212.       table1d1.asDateTime := Date + 2; {or table1d1.value := date + 2;}
  213.       table1d2.asDateTime := Date - 2; 
  214.       t1 := table1d1.asDateTime;
  215.       t2 := table1d2.asDateTime;
  216.       table1d3.asInteger := trunc(double(t1) - double(t2));
  217.     end;
  218.  
  219.  
  220. 11) Q:  Where is the exponent function?
  221.  
  222.     A:  For ExpXY(X, Y) (i.e. Y^X), try:
  223.  
  224.         ExpXY := Exp(Y * Ln(X))
  225.  
  226.         To use a generic function, declare the formal parameters and function
  227.         result as Extended, and the conversions from the actual parameters and
  228.         back to your result variable will be done automatically.  (Note:  Ln is
  229.         the natural logarithm of a number).
  230.  
  231.  
  232. 12) Q:  How do I keep the form in icon form when I run it?  
  233.  
  234.     A:  In the private section of the form object's declaration, put:
  235.  
  236.     PROCEDURE WMQueryOpen(VAR Msg : TWMQueryOpen); message WM_QUERYOPEN;
  237.  
  238.         In the implementation section, put this method:
  239.  
  240.     PROCEDURE TForm1.WMQueryOpen(VAR Msg : TWMQueryOpen);
  241.     begin
  242.       Msg.Result := 0;
  243.     end;
  244.  
  245.     That's it! The form will always remain iconic. OBTW, of course you must 
  246.     set WindowState to wsMinimized in the form's properties initially.
  247.  
  248.  
  249. 13) Q:  I have a form that is a sort of template.  I want to be able to call the 
  250.     same form several times (with different data displayed).  How do I use 
  251.     one form several times?
  252.  
  253.     A:  You need to make modeless window like this:
  254.  
  255.     with TMyForm.create(self) do show;
  256.  
  257.     Now we want to control it.  Here is a way to change the caption of each 
  258.     form that is created.  You have access to it through the form's component 
  259.     array.  This example uses an about box (named "box") as the other form.
  260.  
  261.     procedure TForm1.Button1Click(Sender: TObject);
  262.  
  263.     begin
  264.       with tBox.create(self) do show;
  265.       {ComponentCount-1 is needed because it is zero based.}
  266.       (form1.Components[form1.ComponentCount-1] as tForm).caption :=
  267.         'About Box # ' + intToStr(form1.ComponentCount-2);
  268.     end;
  269.  
  270.  
  271. 14) Q:  How can the component that was right clicked be determined while in an 
  272.     event handler of a popup MenuItem?
  273.  
  274.     A:  Use the PopupComponent property of the PopupMenu component to determine 
  275.     what control was right clicked.
  276.  
  277.     procedure TForm1.PopupItem1Click(Sender: TObject);
  278.     begin
  279.       Label1.Caption := PopupMenu1.PopupComponent.ClassName;
  280.     end;
  281.  
  282.     The form's ActiveControl property can also be used, however,  the active 
  283.     control may not necessarily be the control that caused the popup menu to 
  284.     appear. 
  285.  
  286.  
  287. 15) Q:  How can I capture windows messages and process them before my 
  288.     application.run line is executed?
  289.  
  290.     A:  The following project source demonstrates how to get Window messages 
  291.     before the application's window procedure is called. It is rare, if ever, 
  292.     that this needs to be done.  In most cases assigning a procedure to the 
  293.     Application.OnMessage will accomplish the same thing.
  294.  
  295.     program Project1;
  296.  
  297.     uses
  298.         Forms, messages, wintypes, winprocs,
  299.       Unit1 in 'UNIT1.PAS' {Form1};
  300.  
  301.  
  302.     {$R *.RES}
  303.  
  304.     var
  305.         OldWndProc: TFarProc;
  306.  
  307.     function NewWndProc(hWndAppl: HWnd; Msg, wParam: Word;
  308.                      lParam: Longint): Longint; export;
  309.       begin
  310.         result := 0; { Default WndProc return value }
  311.         {*** Handle messages here; The message number is in Msg ***} 
  312.         result := CallWindowProc(OldWndProc, hWndAppl, Msg,                             wParam, lParam);
  313.       end;
  314.  
  315.     begin
  316.         Application.CreateForm(TForm1, Form1);
  317.         OldWndProc := TFarProc(GetWindowLong(Application.Handle,
  318.                   GWL_WNDPROC));
  319.         SetWindowLong(Application.Handle, GWL_WNDPROC,
  320.                   longint(@NewWndProc));
  321.         Application.Run;
  322.     end.
  323.  
  324.  
  325. 16) Q:  How do I use a case statement to determine which object calls the 
  326.     procedure?
  327.  
  328.     A:  Use the object's TAG property.  You set the value of the tag property of 
  329.     each object so that you know what it is.  (Using constants that describe 
  330.     the object is ideal.)
  331.  
  332.     Note:  This code assumes that only a tButton will call the procedure.
  333.  
  334.     case (sender as tButton).tag of
  335.       0:  blah;
  336.       1:  blah_blah;
  337.     end;
  338.  
  339.  
  340. 17) Q:  How can you do scrolling functions in a TForm component using keyboard 
  341.     commands?  For example, scrolling up and down when a  PgUp or PgDown is 
  342.     pressed.  Is there some simple way to do this or does it have to be 
  343.     programmed by capturing the keystrokes and manually responding to them.
  344.  
  345.     A:  Form scrolling is accomplished by modifying the VertScrollbar or 
  346.     HorzScrollbar Postion properties of the form.  The following code 
  347.     demonstrates how to do this:
  348.  
  349.       procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  350.       Shift: TShiftState);
  351.       const
  352.         PageDelta = 10;
  353.       begin
  354.         With VertScrollbar do
  355.           if Key = vk_Next then  Position := Position+PageDelta
  356.           else if Key = vk_Prior then Position := Position-PageDelta;
  357.       end;
  358.  
  359.  
  360. 18) Q:  How do I transfer the text in a TMemo component on a form to a TMemofield 
  361.     in a Paradox table?
  362.  
  363.     A:  Here is an example.
  364.  
  365.     procedure TForm1.Button1Click(Sender: TObject);
  366.     var
  367.       t: TTable;
  368.     begin
  369.     t := TTable.create(self);
  370.     with t do
  371.       begin
  372.         DatabaseName := 'MyAlias'; {personal alias}
  373.           TableName := 'MyTbl.db';
  374.         open;
  375.         edit;
  376.         insert;
  377.         fieldByName('TheField').assign(memo1.lines); {This is it!}
  378.         post; {required!!!}
  379.         close;
  380.       end;  { End of the with statement. }
  381.     end;
  382.  
  383.  
  384. 19) Q:  How do I make an Fixed Length ASCII text table from a table?
  385.  
  386.     A:  Like this:
  387.  
  388.     procedure TForm1.Button1Click(Sender: TObject);
  389.     var
  390.       t1, t2: tTable;  {t1 = PW table; t2 = ASCII version}
  391.     begin
  392.       t1 := tTable.create(self);
  393.       with t1 do
  394.       begin
  395.         DataBaseName := 'pw'; { Personal Alias for Paradox Directory }
  396.         tableName := 'customer.db'; { Source Table }
  397.         open;
  398.       end;    
  399.       t2 := tTable.create(self);
  400.       with t2 do
  401.       begin
  402.         DataBaseName := 'pw'; { Personal Alias for Paradox Directory }
  403.         tableName := 'asdf.txt';
  404.         TableType := ttASCII;
  405.  
  406.         createTable; 
  407.         open;
  408.         edit;
  409.         BatchMove(t1, batCopy);
  410.         close;
  411.       end;
  412.       t1.close;
  413.     end;
  414.  
  415.  
  416. 20) Q:  How do I set a format for a data field?
  417.  
  418.     A:  Select the table object, and double click.  Select the field that you 
  419.     want to format.  Use the DisplayFormat and the EditFormat properties to 
  420.     do what you want.  DisplayFormat works for when the field does not have 
  421.     focus.  EditFormat works for when the field has focus.  Use the commands 
  422.     as you would for the first parameter of the FormatFloat function, but 
  423.     without the quotes.
  424.  
  425.  
  426. 21) Q:  How do I format a number to place commas as a thousanth's separator?
  427.  
  428.     A:  If you are not using Delphi, try this code:
  429.  
  430.     function FormatNumber(l: longint): string;
  431.     var
  432.       len, count: integer;
  433.       s: string;
  434.     begin
  435.       str(l, s);
  436.       len := length(s);
  437.       for count := ((len - 1) div 3) downto 1 do
  438.         begin
  439.           insert(',', s, len - (count * 3) + 1);
  440.           len := len + 1;
  441.         end;
  442.       FormatNumber := s;
  443.     end;
  444.  
  445.         If you are using Delphi, there is, of course, the easy way:
  446.  
  447.     function FormatNumber(l: longint): string;
  448.  
  449.     begin
  450.       FormatNumber := FormatFloat('#,##0', StrToFloat(IntToStr(l)));
  451.     end;
  452.  
  453.  
  454. 22) Q:  I have a CPU intensive function.  I want to be able to check to see if 
  455.     the user wants to cancel.  How do I do that?
  456.  
  457.     A:  Call Application.ProcessMessages from time to time in your code.
  458.  
  459.  
  460. 23) Q:  How do you extract the high or low order byte from a word?  How do you 
  461.     insert it?  
  462.  
  463.     A:  There are built in methods hi() and lo() for extracting, but for those 
  464.     that want to know how to do it on their own, here it is in its most 
  465.     efficient form (if I do say so myself <G>).  The functions for inserting
  466.     bytes are not in Delphi.  
  467.  
  468.     Note:  Assembler functions return the contents of the AX register.
  469.  
  470.     function GetHiByte(w: word): byte; assembler;
  471.     asm
  472.        mov ax, w
  473.        shr ax, 8
  474.     end;
  475.  
  476.     function GetLoByte(w: word): byte; assembler;
  477.     asm
  478.        mov ax, w
  479.     end;
  480.  
  481.     function SetHiByte(b: byte; w: word): word; assembler;
  482.     asm
  483.        xor ax, ax
  484.        mov ax, w
  485.        mov ah, b
  486.     end;
  487.  
  488.     function SetLoByte(b: byte; w: word): word; assembler;
  489.     asm
  490.        xor ax, ax
  491.        mov ax, w
  492.        mov al, b
  493.     end;
  494.    
  495.     Another way of doing it (with an example of its use):  
  496.  
  497.     Type
  498.        TWord2Byte = record
  499.                   Lo,Hi: Byte;
  500.            end;
  501.  
  502.     var W: Word;
  503.          B: Byte;
  504.     begin
  505.        W := $1234;
  506.        B := TWord2Byte(W).Hi;
  507.        writeln(TWord2Byte(W).Hi);
  508.        { going back }
  509.        TWord2Byte(W).Lo := $67;
  510.        TWord2Byte(W).Hi := $98; { no shl needed! }
  511.     end.
  512.  
  513.  
  514. 24) Q:  I have an OBJ file that has several assembler routines compiled into it.
  515.     I wouldn't want to have to rewrite them.  Is there a way to use them in
  516.     a Delphi app?
  517.  
  518.     A:  You don't indicate if these return values or not (in Pascal this 
  519.         matters.)
  520.  
  521.     If they don't, include the following near the front of your code:
  522.  
  523.       Procedure TurnOn;  External;
  524.       Procedure TurnOff; External;
  525.  
  526.     If they return values, use:
  527.  
  528.       Function TurnOn: Integer; External;
  529.       Function TurnOff: Integer; External;
  530.  
  531.     Replace Integer with whatever datatype they return.
  532.     In either case follow that with:
  533.  
  534.       {$L filename.obj}
  535.  
  536.     to link in the obj file.  See also the "linking external assembler code"
  537.     in the on-line help.
  538.  
  539.  
  540. 25) Q:  Which memory model does Delphi use?
  541.  
  542.     A:  Delphi uses a mixed memory model, but it is very close to the "C" large model.  The defaults are:
  543.  
  544.       - Methods are far
  545.       - Procedures in an interface section are far
  546.       - Procedures only used in an implementation section are near
  547.       - Heap data and all pointers in general (including class instances)
  548.         are far
  549.       - Global variables are near (DS based)
  550.       - Procedure parameters and local variables are near (SS based)
  551.       - Procedures declared FAR or EXPORT are far
  552.       - Virtual memory tables are far for the new class model and near for
  553.         the old
  554.  
  555.     This scheme has been used by Borland Pascal for a very long time. I find
  556.     it flexible and efficient.
  557.  
  558.     Since all public procedures, methods and pointers are 32bit already, 
  559.     Delphi32 won't have to change any of that.  It's likely that Delphi32 
  560.     will switch to 32bit addressing for the data and stack segments too, 
  561.     but that shouldn't affect any of your code either.  What will affect it
  562.     is the change of Integer from 16 to 32 bit.
  563.  
  564.  
  565. 26) Q:  If a component doesn't handle the windows messages that I need it to 
  566.     handle, do I have to write my own version that passes the messages that 
  567.     I need, or is there way to tap (from a TForm or else where) into the 
  568.     message loop, and grap what I need?
  569.  
  570.     A:  To respond to, say, the wm_size message, you would add:
  571.  
  572.      procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
  573.  
  574.     to your component.  Then you could have:
  575.  
  576.      procedure TWhateverComponent.WMPaint(var Message: TWMPaint);
  577.      begin
  578.         {have your way with the component}
  579.      end;
  580.  
  581.     This will work for any windows message.  Most components respond to the 
  582.     more popular messages already, and you can override their event handlers.
  583.  
  584.  
  585. 27) Q:  Borland decided that accessing environment variables from Windows 
  586.     Programs is a Bad Thing.  Why do they force you to use the "obsolete" 
  587.     WinDos unit?
  588.  
  589.     A:  Use the GetDOSEnvironment() call from the API.
  590.  
  591.  
  592. 28) Q:  How would I write a basic screen saver (like, blank the screen) 
  593.     using Delphi?
  594.  
  595.     A:  An easy implementation would be something like this:
  596.  
  597.     var
  598.       f: tForm;
  599.  
  600.     begin
  601.       f := tForm.create(self);
  602.       f.WindowState := wsMaximized;
  603.       f.color := black;
  604.       f.borderStyle := bsNone;
  605.       f.show;
  606.     end;
  607.  
  608.     There is more to do, of course.  You must have a way back from there.  
  609.     Perhaps an actual form that has a mouse click event programmed to 
  610.     f.close it.  Also, you want to hide the mouse.  Etc, etc.  But, this 
  611.     answers the question.
  612.  
  613.  
  614. 29) Q:  How can I determine the Length in pixels of a string after a specific 
  615.     font has been aplied to it?
  616.  
  617.     A:  The two methods, TextHeigh and TextWidth, can be used to determine 
  618.     both the text height and width of a string in pixels.  These methods 
  619.     can only be accessed through components that have a Canvas property 
  620.     such as TForm.  The TPanel component does not have access to its Canvas 
  621.     property by default because it is protected.
  622.  
  623.     If a component doesn't have a Canvas property then The following 
  624.     function will return the text width based on the font passed.
  625.  
  626.       function GetTextWidth(CanvasOWner: TForm; Text : String;
  627.                                  TextFont :  TFont): Integer;
  628.       var
  629.          OldFont : TFont;
  630.       begin    
  631.         OldFont := TFont.Create;
  632.         try
  633.           OldFont.Assign( CanvasOWner.Font );
  634.           CanvasOWner.Font.Assign( TextFont );
  635.           Result := CanvasOWner.Canvas.TextWidth(Text);
  636.           CanvasOWner.Font.Assign( OldFont );
  637.         finally
  638.           OldFont.Free;
  639.         end;
  640.       end;
  641.  
  642.  
  643. 30) Q:  Where is the best place to open a splash screen on program start up?
  644.  
  645.     A:  The best place to open a splash screen is in the project source file 
  646.     after the first FormCreate and before the Run  This is  accomplished 
  647.     by creating a form on the fly and then displaying it before the app is 
  648.     actual opened.
  649.  
  650.      program Project1;
  651.  
  652.      uses Forms,  Unit1 in 'UNIT1.PAS' {Form1}, Splash;
  653.  
  654.      {$R *.RES}
  655.      var
  656.        SplashScreen : TSplashScreen;  {in the Splash unit}
  657.  
  658.      begin
  659.        Application.CreateForm(TForm1, Form1);
  660.        SplashScreen := TSplashScreen.Create(Application);
  661.        try
  662.          SplashScreen.Show;
  663.          {
  664.           do other CreatForms or any other processing 
  665.           before the app is to be opened
  666.          }
  667.          SplashScreen.Close;
  668.        finally  {Make sure the splash screen gets released}
  669.          SplashScreen.Free; 
  670.        end;   
  671.        Application.Run;
  672.      end.
  673.  
  674.  
  675. 31) Q:  How do I call a function from a DLL?
  676.  
  677.     A:  In order to call a function you must know it's exact syntax. and setup
  678.     a function type.  For example to call the CallMe function, which accepts
  679.     two integers and returns a string, from MyTest.Dll when a button is 
  680.     pushed, you could use the following code:
  681.  
  682.     procedure TForm1.Button1Click(Sender: TObject);
  683.  
  684.     type
  685.       TCallMeDll = function(a,b: Integer): string;
  686.  
  687.     var
  688.       CallMeDll: TCallMeDll;
  689.       FuncPtr: TFarProc;
  690.       hDll: THandle;
  691.       result: string;
  692.  
  693.     begin
  694.       hDll:=LoadLibrary('Mytestdll.dll');
  695.       FuncPtr:=GetProcAddress(hDLL,'CallMe');
  696.       @CallMeDll:=FuncPtr;
  697.       if @CallMeDll <> nil then
  698.         result:=CallMeDll(4,5);
  699.       FuncPtr:=nil;
  700.       FreeLibrary(hDll);
  701.     end;
  702.  
  703.     Note that w must first load the dll into memory, then we can obtain a 
  704.     pointer to the function, and assign that to the contents of CallMeDll.
  705.     At this point I am checking to see if the ProcAdderss is Nil, this would 
  706.     indicate that the call to GetProcAddress failed.
  707.  
  708.     It is important to note that sometimes you might want to load the 
  709.     library, and get the procedure address once at the begenning of your 
  710.     program, and free the library once at the end.
  711.       
  712.  
  713. 32) Q:  What is a Callback function, and how do I create one?
  714.  
  715.     A:  A call back function is a function which you write, but is called by 
  716.     some other program or module, such as windows.  To create a callback function, you
  717.     must first declare a function type, the funciton itself, and implement 
  718.     the function.  In the interface section:
  719.  
  720.     { In main program interface }
  721.  
  722.     type
  723.       TCallBackFunction = function(s: string): integer;
  724.       CallMe(s: string): integer;
  725.  
  726.     And in the Implementation section:
  727.  
  728.     { In main program implementation }
  729.  
  730.     procedure TestCallBack(CallBackFunction: TCallBackFunction); far; external 'Other';
  731.         { Note that 'other' is a Dll containing the procedure TestCallBack }
  732.  
  733.     function CallMe(s: PChar): integer;
  734.     begin
  735.       { what ever you need to do }
  736.       CallMe := 1; { What ever you need to return }
  737.     end;
  738.  
  739.     procedure TForm1.Button1Click(Sender: TObject);
  740.     begin
  741.       TestCallBack(CallMe);
  742.     end;
  743.  
  744.     Note that in 'Other' you would also declare a function type, and use it
  745.     like this:
  746.  
  747.     { in library Other interface }
  748.  
  749.     type
  750.       TMainFunction = function(s: string): integer;
  751.       TestCallBack(MainFunc: TMainFunction);
  752.  
  753.     { in library Other implementation }
  754.  
  755.     TestCallBack(MainFunc: TMainFunction);
  756.     var
  757.       result: integer;
  758.     begin
  759.       result:=MainFunc('test');
  760.     end;
  761.