Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

2 dimension arrays as procedures parameters

Posted on 1998-09-17
10
Medium Priority
?
202 Views
Last Modified: 2012-05-04
  I have one problem - when I was writing a program which
 multiply two matrixs I can not give an array to a procedure
 as parameter!..
   How can I do it?
0
Comment
Question by:Styler
  • 5
  • 2
  • 2
  • +1
10 Comments
 
LVL 2

Expert Comment

by:omsec
ID: 1215577
simply define a new data type.

Type
  NeededData = Array [1..100] of Byte; {for example}


Var
  TheData : NeededData;

procedure (Param : NeededData) : {ExitTypeHere}
0
 

Expert Comment

by:Raid
ID: 1215578
By your friend, Raid:

This is not possible, BUT, you can however use pointers.

How to do this:

uses
 crt;

var
 sizeofarray: word;
 bytearray: pointer;
 wordarray: pointer;
 longintarray: pointer;

procedure sharearraybyte(index: byte; barray: pointer);
var
 varread, varwrite: byte;
begin
 varwrite := 100;
 mem[seg(barray^):ofs(barray^)+index] := varwrite;
 { in other words, bytearray[index] := varwrite. }
 varread := mem[seg(barray^):ofs(barray^)+index];
 { in other words, varread := bytearray[index]. }
 writeln(varread);
end;

procedure sharearrayword(index: byte; barray: pointer);
var
 varread, varwrite: word;
begin
 varwrite := 2000;
 memw[seg(barray^):ofs(barray^)+(index * 2)] := varwrite;
 { in other words, bytearray[index] := varwrite. }
 varread := memw[seg(barray^):ofs(barray^)+(index * 2)];
 { in other words, varread := bytearray[index]. }
 writeln(varread);
end;

procedure sharearraylongint(index: byte; barray: pointer);
var
 varread, varwrite: longint;
begin
 varwrite := 30000;
 meml[seg(barray^):ofs(barray^)+(index * 4)] := varwrite;
 { in other words, bytearray[index] := varwrite. }
 varread := meml[seg(barray^):ofs(barray^)+(index * 4)];
 { in other words, varread := bytearray[index]. }
 writeln(varread);
end;

begin
 clrscr;
 getmem(bytearray, sizeofarray);
 { in other words, bytearray: array[0 .. sizeofarray-1] of byte }

 getmem(wordarray, sizeofarray);
 { in other words, wordarray: array[0 .. sizeofarray-1] of byte }

 getmem(longintarray, sizeofarray);
 { in other words, longintarray: array[0 .. sizeofarray-1] of byte }

 sharearraybyte(0, bytearray);
 sharearrayword(0, wordarray);
 sharearraylongint(0, longintarray);
 repeat until keypressed;
 freemem(bytearray, sizeofarray);
 freemem(wordarray, sizeofarray);
 freemem(longintarray, sizeofarray);
end.


0
 

Author Comment

by:Styler
ID: 1215579

  Dear Omsec!

  I was asking about 2 dimension arrays (matrix),
  but not about 1 dimension arrays (vectors)!!!..

                      With respects, Deny Styler.
0
Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

 
LVL 2

Expert Comment

by:omsec
ID: 1215580
Type
  FirstArray = Array [xx] of yy;
  DataType = Array [xx] of FirstArray;

Var
  TheData : DataType;

Begin
  TheData[1][1] := 50;
End.

mean something like this ?
0
 

Author Comment

by:Styler
ID: 1215581

  Yes!!!!..
  Now (I hope) you are understanding my question.
0
 

Author Comment

by:Styler
ID: 1215582

   My good friend Raid!
   Your mistake was the same as omsec's but you give me a very good comment from which I can understand how  I can do  what I
want. Thank you very much.
   Also I have another question to you about programming with
pointers. So can you tell me your e-mail?
0
 

Expert Comment

by:Raid
ID: 1215583
Hello Styler, Raid Here.

I am glad you took into suggestion my pointer
like variables.  If you want, you can e-mail me questions on how to further learn pointers, here it is:

arcwolf@mb.sympatico.ca

Thanks.
0
 
LVL 10

Accepted Solution

by:
viktornet earned 90 total points
ID: 1215584
How about this???
     Type
       SomeDataType = Array [1..10, 1..10] of Byte;

procedure (var Param : SomeDataType) ;
begin
  Param[1,1] := 50;
end;

Regards,
Viktor Ivanov
0
 

Author Comment

by:Styler
ID: 1215585


  Very strange! I tried to do this and it works, but
  before it doesnt work.

  Thank you very much.
0
 

Author Comment

by:Styler
ID: 1215586


  Very strange! I tried to do this and it works, but
  before it doesnt work.

  Thank you very much.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In a use case, a user needs to close an opened report by simply pressing the Escape (Esc) key. This can be done by adding macro code in Report_KeyPress or Report_KeyDown event.
There can be many situations demanding the conversion of Outlook OST files to PST format and as such, there is no shortage of automated tools to perform this conversion. However, what makes Stellar OST to PST converter stand above the rest? Let us e…
Integration Management Part 2
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question