Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

2 dimension arrays as procedures parameters

Posted on 1998-09-17
10
Medium Priority
?
199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

By default Outlook 2016 displays only one time zone in the Calendar. The following article explains how to display two time zones in one calendar view.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

721 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