Http://www.ccw.com.cn/applic/prog/htm2003/20030423_096DZ.htm
Convert data of the ADO control to a variant array
Use the clientdataset datarequest method to upload the variant array
Trigger the ondatarequest event of datasetprovider on the server, and parse the uploaded variant array in ondatarequest.
Number of operations performed on the Root Node of the ADO control on the server
Returns the result of the operation to the variant array and returns the client.
The client parses the variant array and displays the data.
// Convert parameters to a variant array
Function parameterstovariant (PAR: tparameters; procedurename: variant): olevariant;
VaR
Tmpv: variant;
N, I: integer;
Begin
Tmpv: = vararraycreate ([0, par. Count * 5 + 1], varvariant );
Tmpv [0]: = procedurename;
Tmpv [par. Count * 5 + 1]: = 'this is fro 93 ';
N: = 0;
I: = 0;
While par. Count> I do begin
Tmpv [n + 1]: = par. items [I]. Name;
Tmpv [n + 2]: = par. items [I]. datatype;
Tmpv [N + 3]: = par. items [I]. direction;
Tmpv [n + 4]: = par. items [I]. size;
Tmpv [n + 5]: = par. items [I]. value;
I: = I + 1;
N: = N + 5;
End;
Result: = tmpv;
End;
//// Convert the variant array to parameters
Function varianttoparameters (input: variant; par: tparameters): variant;
VaR
N, I: integer;
Begin
N: = 0;
I: = 0;
While vararrayhighbound (input, 1)> (n + 5) Do begin
Par. createparameter (input [n + 1], input [n + 2], input [N + 3], input [n + 4], input [n + 5]);
N: = N + 5;
End;
Result: = true;
End;
// The general purpose of Proc is called by.Program
Procedure midasadoproc (myproc: tadostoredproc; myclientdataset: tclientdataset );
VaR
INS, outs: variant;
Begin
INS: = parameterstovariant (myproc. parameters, myproc. procedurename );
Outs: = myclientdataset. datarequest (INS );
Myproc. procedurename: = outs [0];
Myproc. Parameters. Clear;
Varianttoparameters (outs, myproc. Parameters );
End;
End.
Function tmidasadoproc. datasetprovider1datarequest (Sender: tobject;
Input: olevariant): olevariant;
Begin
If varisarray (input) then
Begin
If input [vararrayhighbound (input, 1)] = 'this is fro 93' then
Begin // call the Stored Procedure
Form1.caption: = 'proc = '+ input [0];
Self. adostoredproc1.procedurename: = input [0];
Self. adostoredproc1.parameters. Clear;
Varianttoparameters (input, self. adostoredproc1.parameters );
Self. adostoredproc1.execproc; Result: = parameterstovariant (self. adostoredproc1.parameters, self. adostoredproc1.procedurename );
End else
Form1.caption: = 'source information is not unknown in Stored Procedure information ';
End else
Form1.caption: = 'unknown source information ';
End;
Procedure tform1.button1click (Sender: tobject );
Begin
If self. socketconnection1.connected = false then self. socketconnection1.open;
Self. adostoredproc1.parameters. Clear;
Self. adostoredproc1.procedurename: = 'testdelphi '; // modify the name of the stored procedure in the local directory by dynamically calling
Self. adostoredproc1.parameters. createparameter ('ins', ftstring, pdinput, 2000, self. edit1.text );
Self. adostoredproc1.parameters. createparameter ('outs', ftstring, pdoutput, 2000, 'null ');
// The original self. adostoredproc1.execproc; is changed to the following
Midasadoproc (self. adostoredproc1, self. clientdataset1 );
Showmessage ('stored procedure returned '+ self. adostoredproc1.parameters. paramvalues ['outs']);
End;