Solved

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

Posted on 2014-09-17
6
419 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 32

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 25

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
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: …

707 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

13 Experts available now in Live!

Get 1:1 Help Now