In article <31420999.11816...@news.fastlane.net>, THEAnal...@Nfo.Org
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.