Solved

passing array as a parameter

Posted on 2004-04-12
1
802 Views
Last Modified: 2010-04-05
hi, everyone.

my code is this:

procedure TForm1.Beregn(var Vinner: array of TKort);
var
j: integer;
begin
SetLength(Vinner,j);
dosomething with Vinner;
SetLength(Vinner,j);
end;

I call this metdhod this way:

procedure TForm1.Test;
var
Vinner: array of TKort;
begin
Beregn(Vinner);
Continue with my Vinner array that has been changed inside Beregn-method.
end;


But the thing is... I get an error everytime i try to call the SetLength method inside the Beregn method. Incompatible types, it says. Then I thought... is this a pointer-issue?
0
Comment
Question by:Darth_helge
[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
1 Comment
 
LVL 20

Accepted Solution

by:
Madshi earned 500 total points
ID: 10804708
When using an open "array of" array parameter like that you can't change the length of the array. The reason is simple:

procedure TForm1.Test;
var Vinner: array [0..9] of TKort;
begin
  Beregn(Vinner);
end;

What should Delphi do now, if you call SetLength? Do you see the problem? That's why calling SetLength is not supported.

However, you can solve the problem this way:

type TVinnerArr = array of TKort;

procedure TForm1.Beregn(var Vinner: TVinnerArr);
var j: integer;
begin
  SetLength(Vinner,j);
  dosomething with Vinner;
  SetLength(Vinner,j);
end;

procedure TForm1.Test;
var Vinner: TVinnerArr;
begin
  Beregn(Vinner);
end;

This works.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

733 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