Not so long ago I had to switch from FireDac to UniDac components. Of course, there were many questions on implementation.
Version of UniDac 6.2.9 for Rad Studio Delphi XE8
There was a question on the calculated fields. The calculation is based on a large number of data, which is why q1.AfterOpen procedure was chosen, but I also tried to hang the algorithm on the Calc procedure, there are the same errors
So there is the following algorithm (Please see your line-
Fields [mas_n_field [i, 0]]. Asstring: = 'blablabla'; // Error dataset not in edit or insert mode //// ---- OKay ----// in array mas_n_field - number field.):
___________________________________________________________
Code: Select all
Procedure TUniMainModule.Q_for_users1AfterOpen (DataSet: TDataSet);
Var i, j: integer;
S: string;
Begin
If F_adv_setting.U_SG_repl.rowcount> 0 then
Begin
If F_adv_setting.U_CB_enabled.Checked then
Begin
For I: = 0 to kol_use_field do
Begin
If Mas_n_field [i, 0]> 500 then
Begin
Exit;
End
Else
Begin
With Q_for_users1 do
Begin
First;
While not eof do
Begin
//// it is known in advance that q_for_user1 is open
If Fields [mas_n_field [i, 0]]. FieldKind = TFieldKind.fkCalculated then
Begin
Fields [mas_n_field [i, 0]]. Calculated: = true; /////// for reliability
Fields [mas_n_field [i, 0]]. Asstring: = 'blablabla'; // Error dataset not in edit or insert mode //// ---- OKay ----// in array mas_n_field - number field.
End;
Next;
End;
End;
End;
End;
End;
End;
Implement it differently, open dataset on Edit(Please see your line-
Edit; /// Error (exception) "Refresh failed. Found X record" - depending on the request - // does not work.):
______________________________________________________________________________
Code: Select all
Procedure TUniMainModule.Q_for_users1AfterOpen (DataSet: TDataSet);
Var i, j: integer;
S: string;
Begin
If F_adv_setting.U_SG_repl.rowcount> 0 then
Begin
If F_adv_setting.U_CB_enabled.Checked then
Begin
For I: = 0 to kol_use_field do
Begin
If Mas_n_field [i, 0]> 500 then
Begin
Exit;
End
Else
Begin
With Q_for_users1 do
Begin
/// it is known in advance that q_for_user1 is open
Edit; /// Error (exception) "Refresh failed. Found X record" - depending on the request - // does not work.
First;
While not eof do
Begin
If Fields [mas_n_field [i, 0]]. FieldKind = TFieldKind.fkCalculated then
Begin
Fields [mas_n_field [i, 0]]. Calculated: = true; ///// for reliability
Fields [mas_n_field [i, 0]]. Asstring: = 'blablabla';
End;
Next;
End;
Post;
End;
End;
End;
End;
End;
Cut from the procedure to create fields in the query
Code: Select all
With Q_for_users1 do
Begin
FieldDefs.Update;
For i: = 0 to Q_for_users1.FieldDefList.Count - 1 do
Begin
With Q_for_users1.FieldDefList [i] do
If (DataType <> ftUnknown) and not (DataType in ObjectFieldTypes)
Then
CreateField (Q_for_users1, nil,
Q_for_users1.FieldDefList.Strings [i]);
Fields [FieldCount - 1] .Name: = 'TF' + inttostr (i);
Fields [FieldCount - 1] .Visible: = true;
Fields [FieldCount-1] .FieldKind: = TFieldKind (0);
Fields [FieldCount - 1] .DisplayWidth: = 40;
Fields [FieldCount - 1] .Displaylabel: = Field_list [i];
End;
If F_adv_setting.U_CB_enabled.Checked then
Begin
If F_adv_setting.U_SG_repl.RowCount> 0 then
Begin
For i: = 0 to F_adv_setting.U_SG_repl.RowCount - 1 do
Begin
For j: = 0 to FieldCount - 1 do
Begin
If F_adv_setting.U_SG_repl.Cells [0, i] = Fields [j] .Displaylabel
Then
Begin
If Fields [j] .Visible = true then
Begin
Fields [j] .Visible: = false;
End;
End;
End;
End;
For i: = 0 to F_adv_setting.U_SG_repl.RowCount - 1 do
Begin
B: = true;
For j: = 0 to FieldCount-1 do
Begin
If (F_adv_setting.U_SG_repl.Cells [0, i] = Fields [j] .Displaylabel) and (Fields [j] .Visible = true) then
Begin
B: = false;
End;
End;
If b = true then
Begin
Inc (sa);
Q_for_users1.FieldDefs.Add ('f' + inttostr (sa), Q_for_users1.FieldDefs [Q_for_users1.FieldDefList.Count - 1] .DataType);
Q_for_users1.FieldDefList [Q_for_users1.FieldDefList.Count-1]
.CreateField (Q_for_users1, nil, 'f' + inttostr (sa));
Fields [FieldCount-1] .FieldKind: = TFieldKind.fkCalculated;
Fields [FieldCount - 1] .DisplayWidth: = 40;
Fields [FieldCount - 1] .Displaylabel: = F_adv_setting.U_SG_repl.Cells [0, i];
Fields [FieldCount - 1] .Name: = 'f' + inttostr (sa);
Fields [FieldCount - 1] .Calculated: = true;
End;
End
___________________________________________________________________________________
The value of blablabla is used for an example, the assignment will go to the adjacent field, but does not work out even such an option.
What am I doing wrong?
Tell me?