RAD Studio VCL Reference
|
Indicates the type of field whose value the parameter represents.
property DataType: TFieldType;
__property TFieldType DataType;
DataType is set automatically when a value is assigned to the parameter. Do not set DataType for bound fields, as that may cause the assigned value to be misinterpreted.
Read DataType to discover the type of data that was assigned to the parameter. Each possible value of DataType corresponds to a type of database field.
C++ Examples:
/* This example requires a TClientDataSet and a button on a form. Put swSystem in the uses clause for gsAppPath. */ void __fastcall TForm1::Button1Click(TObject *Sender) { for (int I = 0; I < CDS->Params->Count; I++) { if (CDS->Params->Items[I]->IsNull && CDS->Params->Items[I]->DataType == ftInteger) CDS->Params->Items[I]->AsInteger = -1; }} #include <swSystem.hpp> void __fastcall TForm1::FormCreate(TObject *Sender) { CDS->LoadFromFile(gsAppPath + "../CDS.XML"); CDS->Params->CreateParam(ftInteger, "StateParam", ptInput); CDS->Params->CreateParam(ftInteger, "MyParam", ptInput); }
Delphi Examples:
{ This example fills in the parameters of a client dataset from the entries of a list box. } procedure TForm1.Button4Click(Sender: TObject); var I: Integer; ListItem: string; begin { Call FetchParams to ensure parameters reflect server metadata } ClientDataSet1.FetchParams; with ClientDataSet1.Params do begin for I := 0 to Count - 1 do begin ListItem := ListBox1.Items[I]; case Items[I].DataType of ftString: Items[I].AsString := ListItem; ftSmallInt: Items[I].AsSmallInt := StrToIntDef(ListItem, 0); ftInteger: Items[I].AsInteger := StrToIntDef(ListItem, 0); ftWord: Items[I].AsWord := StrToIntDef(ListItem, 0); ftBoolean: begin if ListItem = 'True' then Items[I].AsBoolean := True else Items[I].AsBoolean := False; end; ftFloat: Items[I].AsFloat := StrToFloat(ListItem); ftCurrency: Items[I].AsCurrency := StrToFloat(ListItem); ftBCD: Items[I].AsBCD := StrToCurr(ListItem); ftDate: Items[I].AsDate := StrToDate(ListItem); ftTime: Items[I].AsTime := StrToTime(ListItem); ftDateTime: Items[I].AsDateTime := StrToDateTime(ListItem); end; end; end; end; procedure TForm1.FormCreate(Sender: TObject); begin ListBox1.Items.Add('Here is a string'); ListBox1.Items.Add('4'); ListBox1.Items.Add('3456789'); ListBox1.Items.Add('34'); ListBox1.Items.Add('0'); ListBox1.Items.Add('12.56'); ListBox1.Items.Add('4.23'); ListBox1.Items.Add('99.5'); ListBox1.Items.Add('4/12/53'); ListBox1.Items.Add('7:45:00'); ListBox1.Items.Add('4/12/53 7:45:00'); end;
{ This example requires a TClientDataSet and a button on a form. Put swSystem in the uses clause for gsAppPath. } procedure TForm1.Button1Click(Sender: TObject); var I : Integer; begin { Assign -1 to any integer parameter which does not have a value. } for I := 0 to CDS.Params.Count - 1 do if (CDS.Params.Items[I].IsNull) and (CDS.Params.Items[I].DataType = ftInteger) then { Items is the default property, so you can omit its name } CDS.Params[I].AsInteger := -1; end; procedure TForm1.FormCreate(Sender: TObject); begin CDS.LoadFromFile(gsAppPath + 'CDS.XML'); CDS.Params.CreateParam(ftInteger, 'StateParam', ptInput); CDS.Params.CreateParam(ftInteger, 'MyParam', ptInput); end;
Working with Stored Procedure Parameters
Supplying Parameters at Design Time
Copyright(C) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|