Solved

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

Posted on 2014-09-17
6
444 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
6 Comments
 
LVL 33

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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 100

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 26

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…

840 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