function TForm2.ValueToSql(idx: Integer): String;
var
cn: ShortString;
i, j: Integer;
fs: TFormatSettings;
begin
fs.DecimalSeparator := '.';
fs.ShortDateFormat := 'yyyy/mm/dd';
fs.DateSeparator := '-';
fs.LongTimeFormat := 'hh:nn:ss';
fs.TimeSeparator := ':';
Result := '';
case Form1.tablestruct[idx]._type of
'int', 'bigint', 'numeric', 'decimal', 'float': cn := 'TFloatSpinEdit';
'varchar', 'char', 'nvarchar', 'nchar': cn := 'TEdit';
'text', 'ntext': cn := 'TMemo';
'date', 'time', 'datetime': cn := 'TDateTimePicker';
end;
j := -1;
for i := 0 to Panel1.ComponentCount - 1 do
begin
if Panel1.Components[i].ClassName = cn then
begin
if Panel1.Components[i].Tag = idx then
begin
j := i;
break;
end;
end;
end;
case Form1.tablestruct[idx]._type of
'int', 'bigint', 'numeric', 'decimal', 'float': Result := FormatFloat('0.######', TFloatSpinEdit(Panel1.Components[j]).Value, fs);
'varchar', 'char', 'nvarchar', 'nchar': Result := '''' + StringReplace(TEdit(Panel1.Components[j]).Text, '''', '''''', [rfReplaceAll]) + '''';
'text', 'ntext': Result := '''' + StringReplace(TMemo(Panel1.Components[j]).Lines.Text, '''', '''''', [rfReplaceAll]) + '''';
'date': Result := '''' + DateToStr(TDateTimePicker(Panel1.Components[j]).Date, fs) + '''';
'time': Result := '''' + TimeToStr(TDateTimePicker(Panel1.Components[j]).Time, fs) + '''';
'datetime': Result := '''' + DateTimeToStr(TDateTimePicker(Panel1.Components[j]).DateTime, fs) + '''';
end;
end;