?
Solved

How can I pass an array of record as a parameter?

Posted on 2014-09-17
6
Medium Priority
?
494 Views
Last Modified: 2014-09-22
Hello Guys

Let me give an example where I am stuck.

I have 3 units, A, B, and C

My unit B is a unit only for records and numerate variables.

My Unit B is declared in both units, A and C and it has a record

this way:

TCadPal = record
   id : integer;
  word: string;
  sentence : string;
end;

My unit A has a variable like this:

EstPal : Array of TCadPal;


The Unit C  is a unit only for functions and procedures that can be called / used
from many units of my system. The unit C is a libry function.

I need to develop a function in unit C that could fulfill my array varriable, something like this:

Function FulfillVariableCadPal(MyVar: xxxxxxxx)
Var
  i : Integer
Begin 
  For i := 0 to 5
  Begin 
     SetLength(Myvar, Length(MyVar)+1);
    MyVar[i].id := xxxx
    MyVar[i].word := xxxx
    MyVar[i].sentence := xxxx

   and so on 

  End 
End;

Open in new window


My problem is that I don't know how to, I tried to create  (MyVar: Array of TCadPal;) but the compiler told me

 ULibSQL.pas(6481): E2008 Incompatible types

This error points to this line      SetLength(Myvar, Length(MyVar)+1);

I thanks in advance the help
Alex
0
Comment
Question by:hidrau
[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
6 Comments
 
LVL 35

Expert Comment

by:ste5an
ID: 40328072
Please post a concise and complete example. It may a namespace (unit name) problem..
0
 
LVL 1

Author Comment

by:hidrau
ID: 40328181
Hello,

Well, what I need is only to pass my array of record to my function where it can populate it.

The problem is that I can use this line

SetLength(Myvar, Length(MyVar)+1);

I think the way I am declaring the parameter is wrong but I don't know to the correct way

this is my problem, it is simple but I didn't find the correct way. My array of record will increase dynamically.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 40328195
can you please make three units, A, B and C containing the _minimum_ amount of code required to show the problem and post them here?
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 101

Accepted Solution

by:
mlmcc earned 1000 total points
ID: 40328337
You need to declare the array as a type so you can pass the TYPE into the procedure.

When you declare them in the procedure header you are actually creating an unnamed type  So you now essentially have UnamedType1 - in the procedure header and UnamedType2 in the other declaration. The types don't match to the compiler even though to you they do match.

You will have to add the type to a class and include the class in the library unit.

mlmcc
0
 
LVL 27

Assisted Solution

by:Sinisa Vuk
Sinisa Vuk earned 1000 total points
ID: 40329300
mlmcc is right. you definition in B should be (array type):
TCadPal = record
   id : integer;
  word: string;
  sentence : string;
end;
TCadPalArray = array of TCadPal;

Open in new window


..usage in C:
Function FulfillVariableCadPal(var MyVar: TCadPalArray): Boolean;
Var
   i : Integer;
Begin 
  SetLength(MyVar, 6);
  for i := Low(MyVar) to High(MyVar) do
  begin 
    MyVar[i].id := xxxx
    MyVar[i].word := xxxx
    MyVar[i].sentence := xxxx
  end;
...

Open in new window

0
 
LVL 1

Author Closing Comment

by:hidrau
ID: 40338197
thanks very much
0

Featured Post

Technology Partners: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

752 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