delphi-7 – Traverse inputs with the same name and get all values

Question:

I have a web application in which I input hidden a dynamic number of values through a form to a Delphi action .

In action , I wanted to know a way to get all values with the same name.

When it's a single value , I use request.ContentFields.Values['numero']

I'm passing the form inputs as follows:

<input type="hidden" name="numero[]" value="123" />
<input type="hidden" name="numero[]" value="456" />
<input type="hidden" name="numero[]" value="789" />

But how do I get everyone into action ?

  • The conventional way returns only the content of the first input .
  • I tried to create a dynamic array and pass it to it, but it didn't work.

Answer:

Come on, I don't know what you're doing through Delphi, so I'm going to take an approach that we have in C#.

If you have something like this:

<input type="hidden" name="numero[0]" value="123" />
<input type="hidden" name="numero[1]" value="456" />
<input type="hidden" name="numero[2]" value="789" />

Then you would have something like this in delphi:

type
  TIntegerArray: Array of Integer;

procedure TMinhaClass.MinhaAction(numero: TIntegerArray);
var
  I: integer;
begin
  // podendo então:
  for I := 0 to High(numero) do
  begin
     // fazer o que deseja com "numero[I]".
  end;
end;

This answer is entirely based on speculation. Another point is that the fields must always have an order, without breaks, as something like:

numero[0]
numero[1]
numero[3]

Something like this you would only receive values ​​with index 0 and 1 in your action , the field with index 3 would not receive due to the break. Confirm this too.

Scroll to Top