Solved

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

Posted on 2014-09-17
6
475 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 34

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
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!

 
LVL 101

Accepted Solution

by:
mlmcc earned 250 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 250 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

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…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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