Solved

passing array as a parameter

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

705 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

16 Experts available now in Live!

Get 1:1 Help Now