Board index » delphi » What's wrong with this unit?

What's wrong with this unit?

What's wrong with this unit? I seem to have every part right except the
initialization part. When I
try to compile it, the pascal compiler tells me that I should have an
END statement where the word
initialization occurs. Also, I notice that when I type my code in the
editor, the words interface and implementation are white, but the word
initialization is yellow, just like any other code. The reason
that I wrote this unit is so that I'd have an example of a unit with ALL
of its parts. Isn't there supposed
to be an initialization header, or am I wrong? Could some kind soul
please show me what I did wrong?
TIA.

-----------------------------------------------------------------------------------------------------------------

unit myunit;

interface

type mat = array[1..5] of real;
function determin(mtx:mat):real;

implementation

function determin(mtx:mat):real;
var i,j:integer;
    tot:real;
begin
  tot:=0;
  for i:=1 to 5 do begin
    tot:=tot+mtx[i];
  end;
  determin:=tot;
end;

initialization

j:=35;
end.
-----------------------------------------------------------------------------------------------------------------

--
Patrick D. Rockwell
mailto:prockw...@thegrid.net
mailto:HNHC...@prodigy.net
mailto:patri48...@aol.com

 

Re:What's wrong with this unit?


On Sat, 03 Nov 2001 20:02:43 -0800, "Patrick D. Rockwell"

Quote
<prockw...@thegrid.net> wrote:
>What's wrong with this unit? I seem to have every part right except the
>initialization part. When I
>try to compile it, the pascal compiler tells me that I should have an
>END statement where the word
>initialization occurs. Also, I notice that when I type my code in the
>editor, the words interface and implementation are white, but the word
>initialization is yellow, just like any other code. The reason
>that I wrote this unit is so that I'd have an example of a unit with ALL
>of its parts. Isn't there supposed
>to be an initialization header, or am I wrong? Could some kind soul
>please show me what I did wrong?

Which compiler are you using?  Since you're posting in c.l.p.b I'm
going to guess it's not Delphi.  

The "initialization" keyword was introduced in Delphi 1.0, if you're
using an earlier Borlandish Pascal compiler then you need to use a
begin..end block instead:

unit myunit
interface
...

implementation
...
begin
  j:=35;
end.

Stephen Posey
slpo...@concentric.net

Re:What's wrong with this unit?


Quote
Stephen Posey wrote:
> On Sat, 03 Nov 2001 20:02:43 -0800, "Patrick D. Rockwell"
> <prockw...@thegrid.net> wrote:

> >What's wrong with this unit? I seem to have every part right except the
> >initialization part. When I
> >try to compile it, the pascal compiler tells me that I should have an
> >END statement where the word
> >initialization occurs. Also, I notice that when I type my code in the
> >editor, the words interface and implementation are white, but the word
> >initialization is yellow, just like any other code. The reason
> >that I wrote this unit is so that I'd have an example of a unit with ALL
> >of its parts. Isn't there supposed
> >to be an initialization header, or am I wrong? Could some kind soul
> >please show me what I did wrong?

> Which compiler are you using?  Since you're posting in c.l.p.b I'm
> going to guess it's not Delphi.

Yes. BP7.01.

Quote
> The "initialization" keyword was introduced in Delphi 1.0, if you're
> using an earlier Borlandish Pascal compiler then you need to use a
> begin..end block instead:

Ok, thanks.

Quote

> unit myunit
> interface
> ...

> implementation
> ...
> begin
>   j:=35;
> end.

> Stephen Posey
> slpo...@concentric.net

--
Patrick D. Rockwell
mailto:prockw...@thegrid.net
mailto:HNHC...@prodigy.net
mailto:patri48...@aol.com

Re:What's wrong with this unit?


You need to declare j as a untit variable instead of a local variable inside the function scope , such as:

interface
Var
   j:integer;

Quote
"Patrick D. Rockwell" wrote:
> What's wrong with this unit? I seem to have every part right except the
> initialization part. When I
> try to compile it, the pascal compiler tells me that I should have an
> END statement where the word
> initialization occurs. Also, I notice that when I type my code in the
> editor, the words interface and implementation are white, but the word
> initialization is yellow, just like any other code. The reason
> that I wrote this unit is so that I'd have an example of a unit with ALL
> of its parts. Isn't there supposed
> to be an initialization header, or am I wrong? Could some kind soul
> please show me what I did wrong?
> TIA.

> -----------------------------------------------------------------------------------------------------------------

> unit myunit;

> interface

> type mat = array[1..5] of real;
> function determin(mtx:mat):real;

> implementation

> function determin(mtx:mat):real;
> var i,j:integer;
>     tot:real;
> begin
>   tot:=0;
>   for i:=1 to 5 do begin
>     tot:=tot+mtx[i];
>   end;
>   determin:=tot;
> end;

> initialization

> j:=35;
> end.
> -----------------------------------------------------------------------------------------------------------------

> --
> Patrick D. Rockwell
> mailto:prockw...@thegrid.net
> mailto:HNHC...@prodigy.net
> mailto:patri48...@aol.com

Other Threads