Solved

2 dimension arrays as procedures parameters

Posted on 1998-09-17
10
192 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
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 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
audio record to file 4 1,115
qrdesign delphi 5 pdf 5 463
Intraweb submit form as a POST request 4 328
my activex application give System Error.  Code: 5.  Access is denied 16 131
This article explains the steps required to use the default Photos screensaver to display branding/corporate images
In case you ever have to remove a faulty web part from a page , add the following to the end of the page url ?contents=1
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

828 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