Solved

2 dimension arrays as procedures parameters

Posted on 1998-09-17
10
198 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
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 30 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
Part One of the two-part Q&A series with MalwareTech.
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

617 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