Johni Douglas Marangon
Johni Douglas Marangon

Reputation: 587

Call procedure or funcion passing a pair of value in array parameter

I need to pass a pair of value in array parameter function.

It is possible to call this form?

Call

Resul:= Validate( ['Johni', 18], ['Douglas', 22], ['Marangon', 19], [Dani, 29] )

Implementation

function Validate( /* Here, include pair array parameter */ ): Boolean
begin
  // Implemetation  
end;

The solution find.

TData = record
  Name: string;
  Age: Integer; 
  cosntructor Add( const AName: string; const AAge: Integer );
end;

cosntructor TData.Add( const AName: string; const AAge: Integer );
begin
  Name:= AName
  Age:= AAge;
end;

function Validate( const Array of TData ): Booelan;
begin
  // implemtation
end;

Result:= Validate( [ TData.Add( 'Johni', 18 ), TData.Add('Douglas', 22), TData.Add('Marangon', 19) TData.Add(Dani, 29) ] );

Thank you.

Upvotes: 0

Views: 206

Answers (1)

Rob Kennedy
Rob Kennedy

Reputation: 163277

No, it's not possible to use array notation to construct records. Array notation only constructs arrays and sets. Instead, you might take inspiration from the Point or Rect functions and make a standalone function that builds TData instances:

function Data(const Name: string; Age: Integer): TData;
begin
  Result.Name := Name;
  Result.Age := Age;
end;

It would give you more concise notation than calling methods of the TData type:

Validate([Data('Johni', 18), Data('Douglas', 22), Data('Marangon', 19),
          Data(Dani, 29)]);

Upvotes: 2

Related Questions