4 Turbo PASCAL Questions for the more advanced. 
Author Message
 4 Turbo PASCAL Questions for the more advanced.


says...
-
-Question #1:
-   Can someone tell me the differences between using New/Destroy and
-GetMem/FreeMem?  I see everyone on this group using GetMem/FreeMem but
in my
-classes all we are taught is New/Destroy.

     Standard Pascal uses the procedures new() and dispose() to handle
dynamic memory.  Given a pointer variable (of any type), these procedures
allocate (or deallocate) the appropriate amount of memory for the thing
pointed to (sorry about that phrase).  I believe GetMem and FreeMem are
Borland extensions that need to be told how much memory to get or free,
and are thus somewhat more dangerous, and definitely less portable.

-Question #2:
-   A while back I remember glancing at one of my text books on pascal
and seeing
-something like "PROCEDURE Foo( Bar : PROCEDURE (t:Char; I:integer);" and
this
-would allow you to pass any procedure to Foo that was defined like
"(t:Char;
-I:integer)" so that you could call Bar as though it were that other
procedure.
-   I can't remember which text book had the information (I have 4 and
each over
-900 pages).
-   Any suggestions?

     This is the Standard Pascal method of passing "procedure
parameters".  An example of where this might be useful -- you can write a
procedure to integrate a function by using, say, the trapezoidal rule.  
It will integrate any function you pass to it.  By using a function
parameter, your "integral" function will be able to integrate any other
function you might be able to code.

   FUNCTION integral (F : FUNCTION (x : real) OF real;
                      lowlimit, hilimit : real);

    BEGIN   { integral }
     { compute the integral of F for x between lowlimit and hilimit }
    END;

    FUNCTION myfunction (x : real) : real;

    BEGIN   { myfunction }
     myfunction := 1 + sin (sin (x))
    END;
{ more code }
    writeln ('The integral of 1 + sin(sin(x)) from 0 to 1 is ',
             integral (myfunction, 0, 1));

Bob Schor
Pascal Enthusiast

Quote:
>Question #3:
>   In the TP 7 help there are built in procedures that have optional
parameters.
>I have seen a few functions, like I think "Allocated" (not "allocate"),
that
>return a boolean value if the user has put a variable on the command
line of a
>function/procedure, but I cannot figure out how to define a
procedure/function
>that can do this.

>Question #4:
>   I have examples of how to compile a PASCAL file to .com in TP 3,
however TP 7
>won't let me do that and I don't have access to a TP 3 compiler anymore.
>   And at this very moment I don't have access to my TP 3 examples to
show you
>what won't work in TP 7.  Sorry. . . :(

>--
>Plase POST all replies as I have not given a real e-mail address in the
header,
>and others may want answers to my questions.



Wed, 18 Jun 1902 08:00:00 GMT  
 4 Turbo PASCAL Questions for the more advanced.
I believe GetMem and FreeMem are
Quote:
>Borland extensions that need to be told how much memory to get or free,
>and are thus somewhat more dangerous, and definitely less portable.

 Why less portable? Would you describe C's 'malloc' (which does the same thing)
as non-portable? A byte is a byte on whatever platform you are working on.
Unfortunatly, Turbo Pascal is far from portable simply because it is not as
standardized as C/C++. Too many people regard it as a teaching language when
in fact TP is a very extensive and respectable compiler with most of the
features you would find in C.

Tim Lewis.



Wed, 18 Jun 1902 08:00:00 GMT  
 4 Turbo PASCAL Questions for the more advanced.

New/Dispose vs GetMem/FreeMem:
 ...
Quote:
>Example for GetMem/FreeMem.

><********* Start of Code *********>
>Program Mem_Demo;
>{$R-}

Type
  Rec = Record
    Field1 : String;
    Field2 : Integer;
  End;
  RecAry      : Array[1..1] of Rec;
 ...

Quote:

>When using this form of dynamic allocation, you need to make sure that
>you turn off Range Checking.  If you do not, you will get a range check
>error as soon as you try to access element #2.

AFAIR, if one uses instead :

     RecAry      : Array[1..65520 div SizeOf(Rec)] of Rec;

then rangechecking can be left on, which is a Good Thing, although it
will be ineffective in a RecAry.  Just possibly that should be a 65519,
see the manuals.

I think you missed an "^" in

Quote:
>  For Cntr := 1 to Count do
>    Read(InFile, Ary[Cntr] );

...........................^

--
John Stockton, Surrey, UK.  Turnpike v1.12.  MIME.



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Turbo PASCAL Questions for the more advanced.

2. Two advance questions..

3. Advanced Questions For experts only

4. Advanced Questions for EXPERTS2

5. Advanced Questions For EXPERTS only!!

6. Super Advanced Question

7. Pascal- Advanced Power Management Support

8. Pascal- Advanced Power Management Support

9. Advance Pascal Books

10. Pascal Tutorial - Advanced

11. Turbo Pascal Frequently Asked Questions, a monthly pointer

12. Turbo Pascal Frequently Asked Questions, a monthly pointer

 

 
Powered by phpBB® Forum Software