home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / vp11demo.zip / vpbase.rar / doc / FAQ.TXT < prev    next >
Text File  |  1996-10-08  |  17KB  |  431 lines

  1.  
  2.   Virtual Pascal for OS/2 v1.10
  3.   Frequently Asked Questions
  4.   (C) 1996 fPrint UK Ltd
  5.  
  6.  
  7.   The answers to many of these questions can be found in the printed
  8.   manual too.
  9.  
  10. Q: When I write a program, any "read" and "write" statements are syntax
  11.    highlighted along with reserved words.  Why?
  12.  
  13. A: In the new object model, available in the {$Delphi+} state, Read and
  14.    Write are standard directives used in property definitions.  A future
  15.    version of VP/2 will allow you to specify separate colours for
  16.    standard directives and reserved words.
  17.  
  18.  
  19. Q: I am not able to generate any PM programs! The program compiles and
  20.    links OK, but the executable is not a PM program. Am I doing
  21.    something wrong?
  22.  
  23. A: You have to specify the application type to be PM application
  24.    (Options|Linker|Application radio buttons).  Alternatively, you can
  25.    specify the {$PMTYPE Parm} directive to set the application type.
  26.  
  27.  
  28. Q: I have just created a Presentation Manager application, and I want to
  29.    debug it using Virtual Pascal.  Once I get past the point where the
  30.    message queue is created, the system hangs!  What do I do wrong?
  31.  
  32. A: OS/2 Presentation Manager programs can only be debugged safely if you
  33.    run Virtual Pascal in a Full Screen session or if you run VP/PM.  VP/Txt
  34.    in a window on the desktop should be used to debug text-mode applications
  35.    only.
  36.  
  37.  
  38. Q: The clock PM apps compiles and runs fine, but the PM game triplex compiles,
  39.    but does nothing. It's there as a process but there is no window.
  40.  
  41. A: The compiler is not able to find the resource files required by the
  42.    application. You have either to change to the directory where your
  43.    resource file is located or include this directory into
  44.    Options|Directories|Resource directories input box. Also check the
  45.    messages in the Messages window.
  46.    Compilation should include the following stages:
  47.    Compiling...
  48.    Linking...
  49.    Compiling resources... (if there is no binary resource file or the resource
  50.                            script file is newer than the binary resource)
  51.    Binding resources...   (if binary resource file is found)
  52.    Success.
  53.  
  54.  
  55. Q: How can I make VP to compile and add resources to my program? In BP7
  56.    under Windows I use the {$R filename.res} directive.
  57.  
  58. A: You can use the $R statement in VP as well.  Make sure that the
  59.    .RES file in question is available in either the current directory
  60.    or in a directory listed in the Options|Directories|Resource Dirs
  61.    entry field.
  62.  
  63.  
  64. Q1: I want to port a UI unit I wrote using Turbo Pascal to VP. In it I
  65.     need to write directly to the screen. How can I do this in VP?
  66.  
  67. Q2: VP does not compile "absolute $B800:$0000" for video memory. I tried
  68.     defining the addresses through variables, but then I receive a RUNTIME
  69.     error #216.
  70.  
  71. A:  Absolute memory addresses have no meaning in protected mode, so they
  72.     are not supported. You can use the following code to obtain a pointer
  73.     to the logical screen buffer, write something to it and then show
  74.     its contents.
  75.  
  76. ===Cut===
  77.  
  78. { Fills entire screen with character 'A' }
  79.  
  80. uses Os2Base, Use32;
  81.  
  82. type
  83.   PScreenBuffer = ^TScreenBuffer;
  84.   TScreenBuffer = array [0..7999] of record
  85.     Ch:   Char;
  86.     Attr: Byte;
  87.   end;
  88.  
  89. var
  90.   I: Integer;
  91.   BufSize: SmallWord;
  92.   ScreenBuffer: Pointer;
  93. begin
  94.   VioGetBuf(ScreenBuffer, BufSize, 0);   { Get logical screen buffer address }
  95.   SelToFlat(ScreenBuffer);               { Convert it from selector:offset form to flat }
  96.   for I := 0 to BufSize div 2 - 1 do
  97.     with PScreenBuffer(ScreenBuffer)^[I] do
  98.     begin
  99.       Ch := 'A';        { 'A' }
  100.       Attr := $4F;      { White on red }
  101.     end;
  102.   VioShowBuf(0,        { Buffer offset }
  103.              BufSize,  { Length in bytes to show }
  104.              0);       { Vio handle - should be 0 for text mode apps }
  105. end.
  106. ===Cut===
  107.  
  108. Q: The following code brings up the error-message: Error 26: Type mismatch
  109.  
  110. uses Dos;
  111.   var Year,Month,Day,DayOfWeek: Word;
  112. begin
  113.   GetDate(Year,Month,Day,DayOfWeek);
  114. end.
  115.  
  116. A: You have to include the Use32 unit in uses of each unit. Please refer
  117.    to the manual for details.
  118.  
  119.  
  120. Q: The Delay function from the Crt unit seems does not work correctly if
  121.    values less then 150 are specified.
  122.  
  123. A: The OS/2 system timer interval is 31ms, which is why it is not
  124.    possible to make a delay less than this value using the OS/2 API.
  125.    VP/2 uses a special routine for small time intervals to make small
  126.    delays. Unfortunately, even this routine cannot be exact in a
  127.    multi-tasking environment like OS/2.
  128.  
  129.  
  130. Q: Ctrl-F2 in BP is like Shift-F4 in VP/2; why not make it the same ?
  131.  
  132. A: The are not quite the same. Since the VP/2 IDE includes some features
  133.    from the standalone debugger, there are 2 functions: Ctrl-F2 and
  134.    Shift-F4.
  135.    Ctrl-F2 - Restart program - is the same as the Turbo Debugger Reset
  136.    program. You should use it to restart a debugging session, and debug
  137.    your program once more.  You can also use it to load a just compiled
  138.    program (BP does not have this feature at all).
  139.    Shift-F4 is like Reset Program in BP, but you are not able to
  140.    run/debug your program without recompilation, since it terminates
  141.    the debugging session and frees the debug information.
  142.  
  143.  
  144. Q: In the integrated debugger, even after termination of the program,
  145.    the session with program output is still available and debugging
  146.    process is still present in the task list. How can I get rid of it?
  147.  
  148. A: After termination of the program, you still can examine the value of
  149.    static variables (typed constant and global variables) and see the
  150.    program's screen output. You can use the Run|Reset program command
  151.    (Shift-F4) to terminate the debugging session and free the debug
  152.    information. It also deletes the screen session of the debugging
  153.    program. However, having done so, further debugging is not possible
  154.    unless you recompile the program.
  155.  
  156.  
  157. Q: Even though the source is compiled, if I load program I can not step
  158.    through the source (The assembler window takes focus). What happens?
  159.  
  160. A: You have to enable {$D+} (Options|Compiler|Debug information is checked).
  161.  
  162.  
  163. Q: Unlike BP, the value of the iteration index becomes 1 more than the
  164.    number of iterations in FOR loop. For example:
  165.  
  166.         for I := 1 to 4 do;
  167.  
  168.    at this point VP says I = 5 whereas TP says I = 4.
  169.    Is there something wrong?
  170.  
  171. A: No, VP generates different code for FOR loops. The value of the FOR
  172.    control variable is not defined by the language and depends on
  173.    different implementations of the compiler. You should not rely on
  174.    the value of the FOR control variable outside the loop body.
  175.  
  176.  
  177. Q: Since VP is a 32-bit compiler and has no 64K restriction on size of
  178.    the variables, I tried to compile a little program like this:
  179.  
  180. ===Cut===
  181. var
  182.   HugeVar: array[0..32*1024*1024] of Byte;
  183. begin
  184.   FillChar(HugeVar, SizeOf(HugeVar), 'A');
  185. end.
  186. ===Cut===
  187.    but receive the following message from LINK386:
  188.    LINK386 :  fatal error L1204
  189.  
  190. A: Use the built-in linker of VP/2 instead of LINK386.  The built-in linker
  191.    does not have the restrictions imposed by LINK386.
  192.  
  193.  
  194. Q: When I compile code containing "DosError", the compiler reports an
  195.    error saying something resembling, "Error: '(' expected" after the
  196.    "DosError" variable, as if it expected arguments, like in a procedure
  197.    call. To work around this, I replaced "DosError" with "Dos.DosError"
  198.    to direct VP to the DOS unit. It compiled successfully this way. Any
  199.    idea why? Should I be using "DosError" in a special way?
  200.  
  201. A: OS/2 has function named DosError, defined in the Os2Base unit.
  202.    Thus, if the Dos unit is included before Os2Base in your Uses clause,
  203.    the DosError function from Os2Base unit is found before the Dos unit
  204.    variable. You have either to put the Dos unit after Os2Base in the
  205.    uses clause or use a fully qualified identifier - the latter being
  206.    the recommended way of resolving the problem.
  207.  
  208.  
  209. Q: I use the following code fragment to search for files, but it never
  210.    returns the volume label.  Am I doing something wrong?
  211. ===Cut===
  212.    FindFirst('*.*', $3F, SR);
  213. ===Cut==
  214.  
  215. A: The volume label is not returned by the OS/2 version of FindFirst.  If
  216.    you want to query the volume label, you need to use the DosQueryFSInfo
  217.    API call:
  218. ===Cut===
  219.    Uses Use32, Os2Def, Os2Base;
  220.    Var
  221.      DriveNumber : Word;
  222.      Buf : Record
  223.        SerialNum : Word;
  224.        VolLabel  : String;
  225.      end;
  226.    Begin
  227.      DriveNumber := 3;  { Drive C }
  228.      DosQueryFSInfo( DriveNumber, fsil_VolSer, Buf, Sizeof( Buf ));
  229.    End;
  230. ===Cut===
  231.  
  232.  
  233. Q: The ChDir standard procedure does not work correctly. If I change my
  234.    directory in a program and leave the program I find the working
  235.    directory unaltered. What is wrong?
  236.  
  237. A: OS/2 maintains a current directory for each process. If you change
  238.    the current directory in your program, it does not affect the current
  239.    directory of the parent process (usually CMD.EXE which is used to run
  240.    your program). That is why when your program terminates, the current
  241.    directory remains the same as it was before running it.
  242.  
  243.  
  244. Q: I have noticed that PathStr have changed from String[79] in BP to
  245.    String. DirStr, NameStr and ExtStr have changed too. Is there a
  246.    reason for that?
  247.  
  248. A: Yes, VP supports HPFS long file names of the OS/2. The length of each
  249.    path component can be up to 255 characters long. That is why PathStr
  250.    and other types in Dos unit have been extended to String type. The
  251.    File and Text variables have been expanded accordingly to hold long
  252.    file names (cf the FileRec and TextRec types in Dos unit).
  253.  
  254.  
  255. Q: I can not declare a variable of the important type REGISTERS.
  256.    Please give me a hint.
  257.  
  258. A: Neither MsDos or Intr from Borland Pascal are supported.
  259.    OS/2 application have no access to the BIOS/DOS API like BIOS/DOS
  260.    interrupts, DPMI, etc. OS/2 performs all file I/O, video and memory
  261.    management tasks itself.
  262.    The only way to support these functions is to emulate all DOS API
  263.    using the OS/2 API which is almost impossible to do. Instead of using
  264.    DOS and BIOS calls you should use base OS/2 API calls, defined in
  265.    the Os2Base unit or make use of the interface functions provided in
  266.    the VPUtils unit.
  267.  
  268.  
  269. Q: What should I do with my 16-bit inline assembler codes?
  270.  
  271. A: Since 16-bit inline codes should be rewritten as 32-bit code,
  272.    you have two alternatives:
  273.      - replace the offending inline statement with an ASM ... END statement;
  274.      - use inline functions/procedures that can be written in Pascal
  275.        (cf inline procedural directive, see the manual for details).
  276.  
  277.  
  278. Q: I have just got some strange test results with the MaxAvail and
  279.    MemAvail functions. Normally MaxAvail <= MemAvail, but in some
  280.    cases MemAvail > MaxAvail...?
  281.  
  282. A: MemAvail and MaxAvail gives you only rough estimates of the remaining
  283.    memory, since system conditions change constantly in a multitasking
  284.    environment. Your results just means that another process (or the
  285.    system itself) has allocated (or freed) some memory between the calls
  286.    to MemAvail and MaxAvail.
  287.  
  288.  
  289. Q: With MemAvail being unreliable, is there a way of accurately finding
  290.    out if my program suffers from a memory loss because I forget to
  291.    free some dynamically allocated memory?
  292.  
  293. A: Yes; the MemUsed function in VPUtils returns the number of bytes
  294.    currently allocated on the heap.
  295.  
  296.  
  297. Q: In many of my old programs, I return $FFFF in a Word variable to
  298.    signal "failure" or "not found".  In Virtual Pascal, a Word is 32 bit so
  299.    my test fails.  What should I do to make the code work with both BP7
  300.    and VP/2?
  301.  
  302. A: Typecast -1 to Word and compare with this value.  In VP, Word(-1) is
  303.    $FFFFFFFF, and in BP, Word(-1) is $FFFF.  For your comparison to work
  304.    in both Borland and Virtual Pascal, it should be
  305. ===Cut===
  306.    If Test <> Word(-1) then
  307.      Writeln('Found');
  308. ===Cut===
  309.  
  310.  
  311. Q: VP.EXE starts from both DOS and OS/2 tasks, and never gives an error
  312.    saying "This program requires OS/2".  This is nice, and I want my
  313.    programs to do the same!  How?
  314.  
  315. A: Any program linked with the built-in linker of VP/2 will behave in this way.
  316.  
  317.  
  318. Q: I have defined a PM dialog, that requires a function of type FnWp as
  319.    a parameter.  I have defined a function of this type, and specify
  320.    the name of the function in the WinDlgBox call.
  321.    When I compile, I get a "Type Conflict" error.  Why?
  322.  
  323. A: Provided the function header is correct, and matches the definition
  324.    in Os2PmApi, you probably use the wrong calling convention.  This
  325.    procedure needs to be called by OS/2, and needs to use the C-style
  326.    calling convention.  Adding the cdecl; procedural directive after the
  327.    function definition will probably make it work.
  328.  
  329.  
  330. Q: I wish to save the current directory when I save my desktop settings,
  331.    just like in Borland Pascal.  How do I do this?
  332.  
  333. A: Check the "Return to last dir" checkbox in the
  334.    Options|Environment|Preferences dialog.
  335.  
  336.  
  337. Q: I have written multithreaded programs using the Beta or EEP version of
  338.    VP/2, and the BeginThread calls do not compile anymore.  What has changed?
  339.  
  340. A: The BeginThread function has changed to take the same parameters as
  341.    in Borland Delphi v2.  This means, that the thread function should be
  342.    declared as
  343.      Function ThreadFunc( P : Pointer ) : Longint;
  344.    In addition to this change, a number of extra parameters are required.
  345.    If you just want to start a thread and use a set of default values that
  346.    normally make sense, you can use VPUtils.VPBeginThread.
  347.  
  348.  
  349. Q: I have enabled Smart Linking to prevent unused functions from taking up
  350.    space in my executable.  If I look at the output file, not all of them
  351.    are removed!  Why?  How can I make this work?
  352.  
  353. A: This requires a bit of explanation:
  354.    The first step of Smart Linking in VP/2 takes place at compile time.
  355.    When Smart Linking is disabled, the compiler generates one object
  356.    module (which is stored in an .OBJ file) per unit and these modules
  357.    are then linked to form the executable.
  358.    When Smart Linking is enabled, one object module per procedure, function
  359.    and typed constant is generated and the result is stored in a .LIB file.
  360.    At link time, only those object modules required by the application are
  361.    linked into the executable.
  362.    To link the executable, the linker needs the main file to be an OBJ file,
  363.    however.  Thus, any functions defined in the main program file are not
  364.    smart linked away.
  365.    If this is a problem, the solution is to have an "empty" main program,
  366.    that only uses one unit and calls the main function of that unit as its
  367.    only action.
  368.  
  369.  
  370. Q: I have a program that uses the new SysUtils unit. When an exception
  371.    occurs, a big red screen pops up!  What is wrong?
  372.  
  373. A: When an exception causes the program to terminate, the termination
  374.    routines can either display the message in Grey on Black as it happens
  375.    for run-time errors, or it can display the message in a full-screen
  376.    window to prevent the user screen from being corrupted by the error
  377.    message.  The default is the last approach; you can change this behaviour
  378.    by setting
  379.      PopupErrors := False;
  380.  
  381.  
  382. Q: I have enabled Exception Location Information in all units, but my
  383.    program crashes without displaying line number information.  Why?
  384.  
  385. A1:Only units compiled in the {$D+,LocInfo+} state will have location
  386.    information available.  If you program crashes in a unit not compiled
  387.    in this state, for example the System unit, no ELI will be displayed.
  388.  
  389. A2:Remember to check the Options|Linker|Generate Location Info checkbox
  390.    in the Options|Linker dialog.
  391.  
  392.  
  393. Q: I have found the OS/2 .SYM files on the OS/2 CD-ROM; how do I make use
  394.    of these in VP/2's debugger?
  395.  
  396. A: Specify the directory containing the files as a parameter to VP. For
  397.    example, if some of the files are in C:\VP11\SYM and some in D:\SYM,
  398.    start VPPM.EXE with
  399.      VPPM.EXE /sC:\VP11\SYM;D:\SYM
  400.    or change the Parameters section in the settings/proprties for the VP
  401.    program objects on the desktop.
  402.  
  403.  
  404. Q: The compiler complains that my $LINKER statement is invalid, though I
  405.    have checked that all the keywords are valid.  Why?
  406.  
  407. A: All statements in a $LINKER statement (or .DEF file) are case sensitive
  408.    and must be entered in upper case.
  409.  
  410.  
  411. Q: How do I determine what type of disk is associated with a particular
  412.    drive letter?
  413.  
  414. A: Call the GetDriveType function of the VPUtils unit with the drive
  415.    letter as the parameter.  This function returns one of the following
  416.    enumerated values:
  417.      dtFloppy    - Floppy disk
  418.      dtHDFAT     - FAT Hard Disk Drive
  419.      dtHDHPFS    - HPFS Hard Disk Drive
  420.      dtInvalid   - Invalid drive
  421.      dtNovellNet - Novell Net drive
  422.      dtCDRom     - CD ROM drive
  423.      dtLAN       - LAN drive
  424.  
  425.  
  426. Q: I would like to get a list of all valid drive letters on a system. How?
  427.  
  428. A: The GetValidDrives procedure in the VPUtils unit returns a set
  429.    containing all valid drive letters.
  430.  
  431.