Solved

passing array as a parameter

Posted on 2004-04-12
1
800 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
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

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

809 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