Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pass unlimited number of parameters to procedure

Tags:

in Delphi the procedure write can handle:

write(TF,st1)

and

write(TF,st1,st2,st3,st4);

I want to declare a procedure that can also do that, what is the syntax?

and the option of:

write(TF,[st1,st2,st3])

is less desirable, though I know how to do that.

the main purpose was to pass ShortStrings into function, that would make a read call from file, and would read at the length of the shortString as defined. however after passing it as variant or in open array the shortString loses its "size" and become 255, which making this pass unusable, for me. but the answer is still got if you want to pass open array.

like image 965
none Avatar asked Jul 24 '11 13:07

none


People also ask

What is a parameter of a procedure?

A parameter represents a value that the procedure expects you to supply when you call it. The procedure's declaration defines its parameters. You can define a procedure with no parameters, one parameter, or more than one. The part of the procedure definition that specifies the parameters is called the parameter list.

How can we pass multiple values to one parameter in SQL Server stored procedure?

In this solution, you need to pass a single comma delimiter string to the stored procedure. Once it is passed, you need to convert the string parameter to xml variable and split it using comma delimiter and then you can query it.

How do I execute a SQL stored procedure with parameters?

Expand the database that you want, expand Programmability, and then expand Stored Procedures. Right-click the user-defined stored procedure that you want and select Execute Stored Procedure. In the Execute Procedure dialog box, specify a value for each parameter and whether it should pass a null value.


1 Answers

Just to complement Cosmin's answer: if the list of parameters are of different types, you could use an variant open array parameter (also know as "array of const"). More on Delphi documentation.

Example (from documentation):

function MakeStr(const Args: array of const): string;
var
  I: Integer;
begin
  Result := '';
  for I := 0 to High(Args) do
     with Args[I] do
        case VType of
            vtInteger:  Result := Result + IntToStr(VInteger);
            vtBoolean:  Result := Result + BoolToStr(VBoolean);
            vtChar:     Result := Result + VChar;
            vtExtended: Result := Result + FloatToStr(VExtended^);
            vtString:   Result := Result + VString^;
            vtPChar:    Result := Result + VPChar;
            vtObject:   Result := Result + VObject.ClassName;
            vtClass:    Result := Result + VClass.ClassName;
            vtAnsiString:  Result := Result + string(VAnsiString);
            vtCurrency:    Result := Result + CurrToStr(VCurrency^);
            vtVariant:     Result := Result + string(VVariant^);
            vtInt64:       Result := Result + IntToStr(VInt64^);
  end;
end;
like image 92
Fabricio Araujo Avatar answered Oct 05 '22 08:10

Fabricio Araujo