Subject RE: [IBO] Re: Creating a Stored Procedure at runtime
Author Gerhardus Geldenhuis
>
>
> At 11:10 AM 04-12-01 +0200, you wrote:
> >Hi
> >I tried it but there does not exist a ParamNames property.
> >I could also not find anything that looked like it would
> >add a parameter.
>
> No; the component gets and populates the Params itself, when the
> statement is prepared. So, call Prepare first, then *read* the
> Params property and do what what you need with your variables in
> AfterPrepare.
>
> Also, be aware that results returned from TIB_StoredProc don't
> show up in Params[] but in Fields[].
>
> regards,
> Helen
>
Thanks I noticed the behaviour when I put the component on the
datamodule. However it does not seem to have the same behaviour
when creating it runtime. Here is the code that I am trying to
now:
var
I: Integer;
s:string;
begin
try
SourceSP:=TIB_StoredProc.Create(DMRep);
SourceSP.IB_Connection:=SourceConnetion;
SourceSP.IB_Transaction:=SourceTransaction;

SourceSP.StoredProcName:='Read_Rep_Log_'+SPName;
for I:=1 to sourcesp.Params.ColumnCount do//reading the params.
s:=s+sourcesp.Params[i].FieldName;
sourcesp.Prepare;
showmessage(s);
sourcesp.Params.ParamByName('IN_UID').asstring:=uid;
SourceSp.ExecProc;

showmessage(inttostr(SourceSP.Fields.ColumnCount));
finally
SourceSP.Free;
end;//try finally

I tried to emulate what happens when I put the component on a form
but I cant get it right. It keeps giving problems like saying parameter
mismatch. It works perfectly when you put the component on a form or
datamodule but not otherwise.

You said I must set my variable in afterprepare. Does that imply
that I must first write a afterprepare event and assign it to the
procedure. That would be the only way to do it since it is not
created at design time.

Groete
Gerhardus