Solved

2 dimension arrays as procedures parameters

Posted on 1998-09-17
10
182 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
Comment Utility
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
Comment Utility
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
Comment Utility

  Dear Omsec!

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

                      With respects, Deny Styler.
0
 
LVL 2

Expert Comment

by:omsec
Comment Utility
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
Comment Utility

  Yes!!!!..
  Now (I hope) you are understanding my question.
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Styler
Comment Utility

   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
Comment Utility
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
Comment Utility
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
Comment Utility


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

  Thank you very much.
0
 

Author Comment

by:Styler
Comment Utility


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

  Thank you very much.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

This article will show you how to create an ISO CD-ROM/DVD-ROM image (*.iso), and MD5 checksum signature, for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5). It's a good idea to compare checksums, because many installations fail because of a corr…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

763 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now