Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

converting SmallInt to Integer

1,151 views
Skip to first unread message

Mary Kituti

unread,
Feb 20, 2002, 5:36:52 AM2/20/02
to
Is there a function that can convert a SmallInt to an Integer and/or
back? Something similar like StrToInt?

thx

- joris

Rudy Velthuis (TeamB)

unread,
Feb 20, 2002, 6:23:38 AM2/20/02
to
In article <3C737C44...@geo.kuleuven.ac.be>, Mary Kituti says...

> Is there a function that can convert a SmallInt to an Integer and/or
> back? Something similar like StrToInt?

No need:

var
Sml: SmallInt;
Int: Integer;
begin
Sml := 17;
Int := Sml;
Int := 1234;
Sml := Int;
--
Rudy Velthuis (TeamB)

Mary Kituti

unread,
Feb 20, 2002, 10:12:20 AM2/20/02
to

"Rudy Velthuis (TeamB)" wrote:

nope, not working, this is my code:

Type
Graster = array of array of Integer;

Procedure TGDataForm.GetGData(var Z:GRaster;var Formcaption:string);
var
i,j : integer;
fileIMG : file of smallint;
begin
...
for i:= 1 to nrow do
for j:= 1 to ncol do
read(fileIMG, Z[i,j]); //-> compile error: incompatible types
'smallint' and 'integer'

Any ideas?

thx

- joris

Sebastian Moleski

unread,
Feb 20, 2002, 11:23:31 AM2/20/02
to
"Mary Kituti" <Mary....@geo.kuleuven.ac.be> wrote in message
news:3C73BCD4...@geo.kuleuven.ac.be...

Add a temporary smallint variable and use that to assign the value. Kinda
like this:

var
i, j: Integer;
dummy: SmallInt;
fileIMG: file of SmallInt;


begin
...
for i := 1 to nrow
do for j := 1 to ncol do

begin
read(fileIMG, dummy);
z[i,j] := dummy;
end;
...

HTH,

sm


Peter Meyer

unread,
Feb 20, 2002, 12:17:31 PM2/20/02
to

> > Any ideas?
>
> Add a temporary smallint variable and use that to assign the value. Kinda
> like this:
>
> var
> i, j: Integer;
> dummy: SmallInt;
> fileIMG: file of SmallInt;
> begin
> ...
> for i := 1 to nrow
> do for j := 1 to ncol do
> begin
> read(fileIMG, dummy);
> z[i,j] := dummy;
> end;
> ...
>
> HTH,
>
> sm

Hi,
this is a "kludge" that works, but now : why does the direct aassignment of a smallint to an integer
not work. curious...
--
Pierre Meyer                        
Laboratoire de Physique des Solides     
Bt. 510, Universite de Paris Sud         
F 91405 ORSAY, FRANCE               
T : (33)-(0)1 69 15 60 62
Fx : (33)-(0)1 69 15 60 86
e-mail : me...@lps.u-psud.fr
homepage : http://www.lps.u-psud.fr/

Sebastian Moleski

unread,
Feb 20, 2002, 12:44:06 PM2/20/02
to

"Peter Meyer" <me...@lps.u-psud.fr> wrote in message
news:3C73DA2A...@lps.u-psud.fr...

>
> > > Any ideas?
> >
> > Add a temporary smallint variable and use that to assign the value.
Kinda
> > like this:
> >
> > var
> > i, j: Integer;
> > dummy: SmallInt;
> > fileIMG: file of SmallInt;
> > begin
> > ...
> > for i := 1 to nrow
> > do for j := 1 to ncol do
> > begin
> > read(fileIMG, dummy);
> > z[i,j] := dummy;
> > end;
> > ...
> >
> > HTH,
> >
> > sm
>
> Hi,
> this is a "kludge" that works, but now : why does the direct aassignment
of a smallint to an integer
> not work. curious...
Read is as semi-generic function. It expects as second and following
parameters an object of the same type the file is composed of. So it's kinda
like this (if it worked):

procedure Read(var f: file of T; var p1, p2, p3...: T);

Since SmallInt and Integer have different byte sizes, the compiler can't
just substitute one for the other and an additional assignment is required.
That's how var parameters work.

HTH,

sm

Rudy Velthuis (TeamB)

unread,
Feb 20, 2002, 1:18:06 PM2/20/02
to
In article <3C73BCD4...@geo.kuleuven.ac.be>, Mary Kituti says...

> for i:= 1 to nrow do
> for j:= 1 to ncol do
> read(fileIMG, Z[i,j]); //-> compile error: incompatible types
> 'smallint' and 'integer'

Of course, this is quite different. You didn't say you wanted to read
from a file. If you'd read the SmallInts as SmallInts, and then stored
them in the array of Integer, you would succeed:

var
sml: SmallInt;

for i:= 1 to nrow do
for j:= 1 to ncol do

begin
read(fileIMG, sml);
Z[i,j] := sml;
end;

--
Rudy Velthuis (TeamB)

0 new messages