Questions tagged [open-array-parameters]

12 questions
11
votes
3 answers

Is a dynamic array of Char allowed when the parameter type is open array of Char?

I was looking at Delphi: array of Char and TCharArray "Incompatible Types" and started experimenting. What I discovered is rather interesting. procedure Clear(AArray: array of Integer); var I: Integer; begin for I := Low(AArray) to High(AArray)…
Kenneth Cochran
  • 11,954
  • 3
  • 52
  • 117
9
votes
5 answers

Cast static array to open array of different element type

(I already asked this at CodeReview where it got closed as off-topic. Hopefully it's on-topic here.) I have a static arrays of a derived type (like LabelsA: array[0..3] of TLabel; in the following sample code) and a routine accepting an open array…
Uli Gerhardt
  • 13,748
  • 1
  • 45
  • 83
9
votes
1 answer

Why can I pass a var of type X to a open array parameter of that type?

Using Delphi XE-2 (all updates applied). I would expect the following code to generate compilation errors on the DoSomething and DoInteger calls, but it doesn't. program OpenArrayQuestion; {$APPTYPE CONSOLE} {$R *.res} uses …
Marjan Venema
  • 19,136
  • 6
  • 65
  • 79
6
votes
1 answer

Why casting an open array parameter to an array type causes E2089 Invalid typecast?

I'm using Delphi 2007 (Pre generics) and I've defined many functions who can be used for all arrays of TObject's descendants, example: function IndexOf(AArray : array of TObject; AItem : TObject) : integer; begin //... end; For passing them…
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
6
votes
1 answer

Cannot pass typed char array to open array of char?

When compiled under Delphi 7 or Delphi XE, the code below complains [DCC Error] Project1.dpr(25): E2010 Incompatible types: 'array of Char' and 'TAChar' According to Rudy's article, it should be allowed to pass typed array to open array ?…
SOUser
  • 3,802
  • 5
  • 33
  • 63
5
votes
3 answers

How to set string (or AnsiString) constant in the TVarRec?

I want to pass the formatting arguments Args into the Format function. I found some examples of that, but I can't find out how to assign string constant in the TVarRec member. The following code fails on compilation with E2089 Invalid…
user532231
1
vote
1 answer

Delphi open array as property index in indexed property

Is it possible to use an open array as index type for indexed properties? unit OpenArrayAsPropertyIndex; interface type TFoo = class private function getBar(Index: array of Integer): String; public // [DCC Error]: E2008 Incompatible…
malom
  • 223
  • 2
  • 11
1
vote
0 answers

How to avoid "E2251 Ambiguous overloaded call to 'MyMethodName'" when using open array parameters?

Sometimes I get "E2251 Ambiguous overloaded call to 'MyMethodName'" when passing open arrays to overloaded methods. Example: TForm1 = class(TForm) procedure FormCreate(Sender: TObject); private procedure Test(AArrA : array of integer);…
Fabrizio
  • 7,603
  • 6
  • 44
  • 104
1
vote
1 answer

Passing constants to a function parameter that is an open array of record

I have a record defined like this: TRec = record S: string; I: Integer; end; I can initialize a constant of this record type like this: const Rec: TRec = (S:'Test'; I:123); Now I have a function that takes an open array of this record…
Alex Egorov
  • 907
  • 7
  • 26
0
votes
5 answers

How can I pass a group of objects to a function for creation?

So I'm working in Delphi 2007 and I am cleaning up my code. I have come to notice that in a great many procedures I declare a number of different variables of the same type. for example the one procedure I am looking at now I declare 4 different…
Tim
  • 1,549
  • 1
  • 20
  • 37
0
votes
1 answer

How to avoid stack overflow when passing an array to a function in C++?

I am working on a code where an array is passed to a function by passing the pointer to the first location. In the function, part of the array is used. This creates an unsafe situation because there is a chance if the caller function does not guess…
0
votes
1 answer

An Oracle stored procedure accept array(table) parameter in package example needed

This question is a part of my question how to pass javascript array to oracle store procedure by ado parameter object I think divide it to 3 small parts will get answer faster. For this question. I know we can declare a table type and use select…