Solved

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

Posted on 2014-09-17
6
426 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Delphi: how to implement a User Shortcut mapper? 1 95
Dev Express grid collapse 2 39
Multiple image collision 13 69
How to build JSON File in Delphi 6 3 17
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…
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

863 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

27 Experts available now in Live!

Get 1:1 Help Now