unit fraparams; {$mode ObjFPC}{$H+} interface uses Classes, SysUtils, LResources, Forms, Controls, db, Grids; type { TfraParams } TfraParams = class(TFrame) SGParams: TStringGrid; procedure SGParamsEditingDone(Sender: TObject); procedure SGParamsSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string); private FParamHistory: TParams; FParams: TParams; procedure AddValueToHistory(P: TParam); procedure ApplyHistoryValues; procedure ApplyValue(P: TParam; aValue: UTF8String); procedure DisplayParams; procedure FillDataTypePicklist; procedure SetParams(AValue: TParams); public constructor Create(aOwner : TComponent); override; Destructor Destroy; override; Property Params : TParams Read FParams Write SetParams; Property ParamHistory : TParams Read FParamHistory; end; implementation uses typinfo, fmtbcd; const colName = 0; colType = 1; colNull = 2; colValue = 3; SupportedParams = [ftString, ftSmallint, ftInteger, ftWord, ftBoolean, ftFloat, ftCurrency, ftBCD, ftDate, ftTime, ftDateTime, ftMemo, ftFixedChar, ftWideString, ftLargeint, ftVariant, ftGuid, ftTimeStamp, ftFMTBcd, ftFixedWideChar, ftWideMemo]; {$R *.lfm} Function DataTypeToString (T : TFieldType) : String; begin Str(T,Result); Delete(Result,1,2); end; Function StringToDataType (aValue : String) : TFieldType; var I : Integer; begin if (Length(aValue)>1) and ((Upcase(Avalue[1])<>'F') or (Upcase(Avalue[1])<>'T')) then aValue:='ft'+aValue; I:=GetEnumValue(TypeInfo(TFieldType),aValue); if I=-1 then Result:=ftUnknown else Result:=TFieldType(I); end; { TfraParams } function CompareParams(Item1, Item2: TCollectionItem): Integer; begin Result:=CompareText(TParam(Item1).Name,TParam(Item2).Name); end; procedure TfraParams.SGParamsEditingDone(Sender: TObject); begin end; procedure TfraParams.ApplyValue(P : TParam; aValue : UTF8String); var T : TFieldType; begin T:=P.DataType; Case T of ftString, ftMemo, ftFixedChar : P.AsString:=aValue; ftWideString, ftFixedWideChar, ftWideMemo : P.AsUnicodeString:=UTF8Decode(aValue); ftSmallint : P.AsSmallInt:=StrToInt(aValue); ftInteger : P.Asinteger:=StrToInt(aValue); ftWord : P.AsWord:=StrToInt(aValue); ftBoolean : P.AsBoolean:=StrToBool(aValue); ftFloat : P.AsFloat:=StrToFloat(aValue); ftCurrency : P.AsCurrency:=StrToCurr(aValue); ftBCD : P.AsBCD:=StrToBCD(aValue); ftDate : P.AsDate:=StrToDate(aValue); ftTime : P.AsTime:=StrToTime(aValue); ftDateTime : P.AsDateTime:=StrToDateTime(aValue); ftLargeint : P.AsLargeInt:=StrToInt64(aValue); ftVariant : P.Value:=aValue; ftGuid : P.AsString:=aValue; ftTimeStamp : P.AsDate:=StrToDateTime(aValue); ftFMTBcd : P.AsFMTBCD:=StrToBCD(aValue); else // Not supported; end; // To make sure we have the correct type P.DataType:=T; end; procedure TfraParams.AddValueToHistory(P : TParam); Var PHist : TParam; begin PHist:=FParamHistory.FindParam(P.Name); if PHist=Nil then PHist:=(FParamHistory.Add as TParam); PHist.Assign(P); end; procedure TfraParams.SGParamsSetEditText(Sender: TObject; ACol, ARow: Integer; const Value: string); Var P : TParam; T : TFieldType; begin Dec(aRow); if (aRow>=0) and (aRow