1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| {* -----------------------------------------------------------------------------
La Fonction DataSetToString prend dans un DataSet, et construit chaine qui contiendra les binomes names=values
@param DataSet contenant une ligne de données
@param Value Chaine qui contiendra la version Texte de la DataBase (names=values)
@return Renvoie un True on a pu extraire les Données
------------------------------------------------------------------------------ }
class function TEpcPersistantDataConverter.DataSetToString(const DataSet: TDataSet; out Value: string): Boolean;
var
iField: Integer;
FieldName, FieldValue: string;
List: TStrings;
Field: TField;
UnQuoteEnd: Boolean;
begin
List := TStringList.Create();
try
Result := Assigned(DataSet) and not DataSet.IsEmpty;
if Result then
begin
// Le Premier Champ c'est l'ID ... on commence à 1 au lieu de 0 !
for iField := 1 to DataSet.FieldCount - 1 do
begin
Field := DataSet.Fields[iField];
FieldName := Field.FieldName;
if not Field.IsNull then
begin
case Field.DataType of
ftBoolean :
FieldValue := BoolToStr(Field.AsBoolean, True);
ftSmallint :
FieldValue := BoolToStr(LongBool(Field.AsInteger), True);
ftInteger, ftWord, ftLargeint, ftAutoInc :
FieldValue := Field.AsString;
ftFloat, ftCurrency, ftBCD :
FieldValue := LocaleStringFloatToStringComponent(Field.AsString);
ftDate, ftTime, ftDateTime :
FieldValue := DateTimeToStringComponent(Field.AsDateTime);
ftString, ftMemo : begin
FieldValue := Field.AsString;
UnQuoteEnd := (Length(FieldValue) > 0) and ((FieldValue[Length(FieldValue)] = #10) or (FieldValue[Length(FieldValue)] = #13));
FieldValue := AnsiReplaceStr(FieldValue, CRLF, QCRLFQ);
if UnQuoteEnd then
FieldValue := ''''+Copy(FieldValue, 1, Length(FieldValue) - 1)
else
FieldValue := ''''+FieldValue+'''';
end
else
raise EPropertyConvertError.CreateFmt(ERR_DATA_TYPE_NO_MANAGE, [FieldName, FieldTypeNames[Field.DataType]]);
end;
List.Add(Format('%s=%s', [FieldName, FieldValue]));
end;
end;
end;
Value := List.Text;
finally
List.Free();
end;
end; |
Partager