Solved

passing array as a parameter

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Machine not responding during CopyFile() 3 98
Path  to current project in Delphi. 2 79
Best Firemonkey component pack 1 101
DBGrid or StringGrid ? 6 88
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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

785 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