Statistiques
| Révision:

root / UnitDeclaration.pas @ 9

Historique | Voir | Annoter | Télécharger (219,571 ko)

1
unit UnitDeclaration;
2

    
3
interface
4

    
5
uses
6
  SysUtils, Classes, DB, DBTables, DbClient, SQLiteTable3, Forms, Windows,
7
  Dialogs, Variants, Math, MidasLib, LbClass, LbCipher, gnugettext;
8

    
9
const
10
  CALORIE = 4.184; // Conversion J -> cal
11
  NDF_CB = 3.0;
12
  NDF_ADF = 2.5;
13
  CoefMAT = 14.73 * 100 * CALORIE / 1000;
14
  CoefMG = 52.4 * 100 * CALORIE / 1000;
15
  CoefMM = -44.6 * 100 * CALORIE / 1000;
16
  dLys = 0.770;
17
  dThr = 0.760;
18
  dMet = 0.846;
19
  dCys = 0.733;
20
  dMetCys = 0.788;
21
  dTrp = 0.772;
22
  dIle = 0.807;
23
  dVal = 0.777;
24
  dLeu = 0.833;
25
  dPhe = 0.842;
26
  dTyr = 0.855;
27
  dPheTyr = 0.847;
28
  dHis = 0.841;
29
  dArg = 0.887;
30
  dAla = 0.773;
31
  dAsp = 0.791;
32
  dGlu = 0.861;
33
  dGly = 0.718;
34
  dSer = 0.807;
35
  dPro = 0.787;
36

    
37
type
38
  TDataModuleDeclaration = class(TDataModule)
39
    ClientDataSetClasses: TClientDataSet;
40
    ClientDataSetClassesId: TIntegerField;
41
    ClientDataSetClassesName: TWideStringField;
42
    ClientDataSetInraAfz: TClientDataSet;
43
    ClientDataSetInraAfzId: TAutoIncField;
44
    ClientDataSetInraAfzName: TStringField;
45
    ClientDataSetInraAfzComment: TStringField;
46
    ClientDataSetInraAfzSource: TStringField;
47
    ClientDataSetInraAfzClass: TIntegerField;
48
    ClientDataSetInraAfzMS: TFloatField;
49
    ClientDataSetInraAfzMM: TFloatField;
50
    ClientDataSetInraAfzMAT: TFloatField;
51
    ClientDataSetInraAfzMG: TFloatField;
52
    ClientDataSetInraAfzCB: TFloatField;
53
    ClientDataSetInraAfzCoefCB: TFloatField;
54
    ClientDataSetInraAfzNDF: TFloatField;
55
    ClientDataSetInraAfzCoefNDF: TFloatField;
56
    ClientDataSetInraAfzADF: TFloatField;
57
    ClientDataSetInraAfzCoefADF: TFloatField;
58
    ClientDataSetInraAfzADL: TFloatField;
59
    ClientDataSetInraAfzAmidon: TFloatField;
60
    ClientDataSetInraAfzSucres: TFloatField;
61
    ClientDataSetInraAfzEB: TFloatField;
62
    ClientDataSetInraAfzdEc: TFloatField;
63
    ClientDataSetInraAfzEMc_EDc: TFloatField;
64
    ClientDataSetInraAfzENc_EMc: TFloatField;
65
    ClientDataSetInraAfzEMt_EDt: TFloatField;
66
    ClientDataSetInraAfzENt_EMt: TFloatField;
67
    ClientDataSetInraAfzEDt_EDc: TFloatField;
68
    ClientDataSetInraAfza: TFloatField;
69
    ClientDataSetInraAfzb: TFloatField;
70
    ClientDataSetInraAfzdNc: TFloatField;
71
    ClientDataSetInraAfzdNt: TFloatField;
72
    ClientDataSetInraAfzLys: TFloatField;
73
    ClientDataSetInraAfzThr: TFloatField;
74
    ClientDataSetInraAfzMet: TFloatField;
75
    ClientDataSetInraAfzCys: TFloatField;
76
    ClientDataSetInraAfzMetCys: TFloatField;
77
    ClientDataSetInraAfzTrp: TFloatField;
78
    ClientDataSetInraAfzIle: TFloatField;
79
    ClientDataSetInraAfzVal: TFloatField;
80
    ClientDataSetInraAfzLeu: TFloatField;
81
    ClientDataSetInraAfzPhe: TFloatField;
82
    ClientDataSetInraAfzTyr: TFloatField;
83
    ClientDataSetInraAfzPheTyr: TFloatField;
84
    ClientDataSetInraAfzHis: TFloatField;
85
    ClientDataSetInraAfzArg: TFloatField;
86
    ClientDataSetInraAfzAla: TFloatField;
87
    ClientDataSetInraAfzAsp: TFloatField;
88
    ClientDataSetInraAfzGlu: TFloatField;
89
    ClientDataSetInraAfzGly: TFloatField;
90
    ClientDataSetInraAfzSer: TFloatField;
91
    ClientDataSetInraAfzPro: TFloatField;
92
    ClientDataSetInraAfzdLys: TFloatField;
93
    ClientDataSetInraAfzdThr: TFloatField;
94
    ClientDataSetInraAfzdMet: TFloatField;
95
    ClientDataSetInraAfzdCys: TFloatField;
96
    ClientDataSetInraAfzdMetCys: TFloatField;
97
    ClientDataSetInraAfzdTrp: TFloatField;
98
    ClientDataSetInraAfzdIle: TFloatField;
99
    ClientDataSetInraAfzdVal: TFloatField;
100
    ClientDataSetInraAfzdLeu: TFloatField;
101
    ClientDataSetInraAfzdPhe: TFloatField;
102
    ClientDataSetInraAfzdTyr: TFloatField;
103
    ClientDataSetInraAfzdPheTyr: TFloatField;
104
    ClientDataSetInraAfzdHis: TFloatField;
105
    ClientDataSetInraAfzdArg: TFloatField;
106
    ClientDataSetInraAfzdAla: TFloatField;
107
    ClientDataSetInraAfzdAsp: TFloatField;
108
    ClientDataSetInraAfzdGlu: TFloatField;
109
    ClientDataSetInraAfzdGly: TFloatField;
110
    ClientDataSetInraAfzdSer: TFloatField;
111
    ClientDataSetInraAfzdPro: TFloatField;
112
    ClientDataSetInraAfzCa: TFloatField;
113
    ClientDataSetInraAfzP: TFloatField;
114
    ClientDataSetInraAfzdP: TFloatField;
115
    ClientDataSetInraAfzdPphy: TFloatField;
116
    ClientDataSetInraAfzNa: TFloatField;
117
    ClientDataSetInraAfzK: TFloatField;
118
    ClientDataSetInraAfzCl: TFloatField;
119
    DataSourceInraAfz: TDataSource;
120
    ClientDataSetIngredients: TClientDataSet;
121
    ClientDataSetIngredientsId: TIntegerField;
122
    ClientDataSetIngredientsName: TWideStringField;
123
    ClientDataSetIngredientsDefinition: TWideStringField;
124
    ClientDataSetIngredientsClass: TIntegerField;
125
    ClientDataSetIngredientsClassName: TWideStringField;
126
    ClientDataSetIngredientsUser: TBooleanField;
127
    ClientDataSetIngredientsModel: TIntegerField;
128
    ClientDataSetIngredientsSource: TWideStringField;
129
    ClientDataSetIngredientsMS: TFloatField;
130
    ClientDataSetIngredientsMS2: TFloatField;
131
    ClientDataSetIngredientsMM: TFloatField;
132
    ClientDataSetIngredientsMAT: TFloatField;
133
    ClientDataSetIngredientsMG: TFloatField;
134
    ClientDataSetIngredientsCB: TFloatField;
135
    ClientDataSetIngredientsNDF: TFloatField;
136
    ClientDataSetIngredientsADF: TFloatField;
137
    ClientDataSetIngredientsADL: TFloatField;
138
    ClientDataSetIngredientsAmidon: TFloatField;
139
    ClientDataSetIngredientsSucres: TFloatField;
140
    ClientDataSetIngredientsEB: TFloatField;
141
    ClientDataSetIngredientsBonus: TFloatField;
142
    ClientDataSetIngredientsdEc: TFloatField;
143
    ClientDataSetIngredientsEDc: TFloatField;
144
    ClientDataSetIngredientsEMc_EDc: TFloatField;
145
    ClientDataSetIngredientsEMc: TFloatField;
146
    ClientDataSetIngredientsENc_EMc: TFloatField;
147
    ClientDataSetIngredientsENc: TFloatField;
148
    ClientDataSetIngredientsdEt: TFloatField;
149
    ClientDataSetIngredientsEDt: TFloatField;
150
    ClientDataSetIngredientsEMt_EDt: TFloatField;
151
    ClientDataSetIngredientsEMt: TFloatField;
152
    ClientDataSetIngredientsENt_EMt: TFloatField;
153
    ClientDataSetIngredientsENt: TFloatField;
154
    ClientDataSetIngredientsEDt_EDc: TFloatField;
155
    ClientDataSetIngredientsEMt_EMc: TFloatField;
156
    ClientDataSetIngredientsENt_ENc: TFloatField;
157
    ClientDataSetIngredientsdNc: TFloatField;
158
    ClientDataSetIngredientsdNt: TFloatField;
159
    ClientDataSetIngredientsLys: TFloatField;
160
    ClientDataSetIngredientsThr: TFloatField;
161
    ClientDataSetIngredientsMet: TFloatField;
162
    ClientDataSetIngredientsCys: TFloatField;
163
    ClientDataSetIngredientsMetCys: TFloatField;
164
    ClientDataSetIngredientsTrp: TFloatField;
165
    ClientDataSetIngredientsIle: TFloatField;
166
    ClientDataSetIngredientsVal: TFloatField;
167
    ClientDataSetIngredientsLeu: TFloatField;
168
    ClientDataSetIngredientsPhe: TFloatField;
169
    ClientDataSetIngredientsTyr: TFloatField;
170
    ClientDataSetIngredientsPheTyr: TFloatField;
171
    ClientDataSetIngredientsHis: TFloatField;
172
    ClientDataSetIngredientsArg: TFloatField;
173
    ClientDataSetIngredientsAla: TFloatField;
174
    ClientDataSetIngredientsAsp: TFloatField;
175
    ClientDataSetIngredientsGlu: TFloatField;
176
    ClientDataSetIngredientsGly: TFloatField;
177
    ClientDataSetIngredientsSer: TFloatField;
178
    ClientDataSetIngredientsPro: TFloatField;
179
    ClientDataSetIngredientsLys_MAT: TFloatField;
180
    ClientDataSetIngredientsThr_MAT: TFloatField;
181
    ClientDataSetIngredientsMet_MAT: TFloatField;
182
    ClientDataSetIngredientsCys_MAT: TFloatField;
183
    ClientDataSetIngredientsMetCys_MAT: TFloatField;
184
    ClientDataSetIngredientsTrp_MAT: TFloatField;
185
    ClientDataSetIngredientsIle_MAT: TFloatField;
186
    ClientDataSetIngredientsVal_MAT: TFloatField;
187
    ClientDataSetIngredientsLeu_MAT: TFloatField;
188
    ClientDataSetIngredientsPhe_MAT: TFloatField;
189
    ClientDataSetIngredientsTyr_MAT: TFloatField;
190
    ClientDataSetIngredientsPheTyr_MAT: TFloatField;
191
    ClientDataSetIngredientsHis_MAT: TFloatField;
192
    ClientDataSetIngredientsArg_MAT: TFloatField;
193
    ClientDataSetIngredientsAla_MAT: TFloatField;
194
    ClientDataSetIngredientsAsp_MAT: TFloatField;
195
    ClientDataSetIngredientsGlu_MAT: TFloatField;
196
    ClientDataSetIngredientsGly_MAT: TFloatField;
197
    ClientDataSetIngredientsSer_MAT: TFloatField;
198
    ClientDataSetIngredientsPro_MAT: TFloatField;
199
    ClientDataSetIngredientsdLys: TFloatField;
200
    ClientDataSetIngredientsdThr: TFloatField;
201
    ClientDataSetIngredientsdMet: TFloatField;
202
    ClientDataSetIngredientsdCys: TFloatField;
203
    ClientDataSetIngredientsdMetCys: TFloatField;
204
    ClientDataSetIngredientsdTrp: TFloatField;
205
    ClientDataSetIngredientsdIle: TFloatField;
206
    ClientDataSetIngredientsdVal: TFloatField;
207
    ClientDataSetIngredientsdLeu: TFloatField;
208
    ClientDataSetIngredientsdPhe: TFloatField;
209
    ClientDataSetIngredientsdTyr: TFloatField;
210
    ClientDataSetIngredientsdPheTyr: TFloatField;
211
    ClientDataSetIngredientsdHis: TFloatField;
212
    ClientDataSetIngredientsdArg: TFloatField;
213
    ClientDataSetIngredientsdAla: TFloatField;
214
    ClientDataSetIngredientsdAsp: TFloatField;
215
    ClientDataSetIngredientsdGlu: TFloatField;
216
    ClientDataSetIngredientsdGly: TFloatField;
217
    ClientDataSetIngredientsdSer: TFloatField;
218
    ClientDataSetIngredientsdPro: TFloatField;
219
    ClientDataSetIngredientsLysd: TFloatField;
220
    ClientDataSetIngredientsThrd: TFloatField;
221
    ClientDataSetIngredientsMetd: TFloatField;
222
    ClientDataSetIngredientsCysd: TFloatField;
223
    ClientDataSetIngredientsMetCysd: TFloatField;
224
    ClientDataSetIngredientsTrpd: TFloatField;
225
    ClientDataSetIngredientsIled: TFloatField;
226
    ClientDataSetIngredientsVald: TFloatField;
227
    ClientDataSetIngredientsLeud: TFloatField;
228
    ClientDataSetIngredientsPhed: TFloatField;
229
    ClientDataSetIngredientsTyrd: TFloatField;
230
    ClientDataSetIngredientsPheTyrd: TFloatField;
231
    ClientDataSetIngredientsHisd: TFloatField;
232
    ClientDataSetIngredientsArgd: TFloatField;
233
    ClientDataSetIngredientsAlad: TFloatField;
234
    ClientDataSetIngredientsAspd: TFloatField;
235
    ClientDataSetIngredientsGlud: TFloatField;
236
    ClientDataSetIngredientsGlyd: TFloatField;
237
    ClientDataSetIngredientsSerd: TFloatField;
238
    ClientDataSetIngredientsProd: TFloatField;
239
    ClientDataSetIngredientsLysd_ENc: TFloatField;
240
    ClientDataSetIngredientsLysd_ENt: TFloatField;
241
    ClientDataSetIngredientsCa: TFloatField;
242
    ClientDataSetIngredientsP: TFloatField;
243
    ClientDataSetIngredientsdP: TFloatField;
244
    ClientDataSetIngredientsdPphy: TFloatField;
245
    ClientDataSetIngredientsNa: TFloatField;
246
    ClientDataSetIngredientsK: TFloatField;
247
    ClientDataSetIngredientsCl: TFloatField;
248
    ClientDataSetIngredientsBE: TFloatField;
249
    DataSourceIngredients: TDataSource;
250
    ClientDataSetComposition: TClientDataSet;
251
    ClientDataSetCompositionFeed: TIntegerField;
252
    ClientDataSetCompositionIngredient: TIntegerField;
253
    ClientDataSetCompositionUser: TBooleanField;
254
    ClientDataSetCompositionIngredientName: TWideStringField;
255
    ClientDataSetCompositionRank: TIntegerField;
256
    ClientDataSetCompositionMS: TFloatField;
257
    ClientDataSetCompositionLevel: TFloatField;
258
    DataSourceComposition: TDataSource;
259
    ClientDataSetPhytase: TClientDataSet;
260
    ClientDataSetPhytaseId: TAutoIncField;
261
    ClientDataSetPhytaseType: TFloatField;
262
    ClientDataSetPhytaseCoef: TFloatField;
263
    DataSourcePhytase: TDataSource;
264
    ClientDataSetFeeds: TClientDataSet;
265
    ClientDataSetFeedsId: TIntegerField;
266
    ClientDataSetFeedsName: TWideStringField;
267
    ClientDataSetFeedsDescription: TWideStringField;
268
    ClientDataSetFeedsPresentation: TIntegerField;
269
    ClientDataSetFeedsBonusC: TFloatField;
270
    ClientDataSetFeedsBonusT: TFloatField;
271
    ClientDataSetFeedsMS: TFloatField;
272
    ClientDataSetFeedsMS2: TFloatField;
273
    ClientDataSetFeedsMM: TFloatField;
274
    ClientDataSetFeedsMAT: TFloatField;
275
    ClientDataSetFeedsMG: TFloatField;
276
    ClientDataSetFeedsCB: TFloatField;
277
    ClientDataSetFeedsNDF: TFloatField;
278
    ClientDataSetFeedsADF: TFloatField;
279
    ClientDataSetFeedsADL: TFloatField;
280
    ClientDataSetFeedsAmidon: TFloatField;
281
    ClientDataSetFeedsSucres: TFloatField;
282
    ClientDataSetFeedsEB: TFloatField;
283
    ClientDataSetFeedsdEc: TFloatField;
284
    ClientDataSetFeedsEDc: TFloatField;
285
    ClientDataSetFeedsEMc_EDc: TFloatField;
286
    ClientDataSetFeedsEMc: TFloatField;
287
    ClientDataSetFeedsENc_EMc: TFloatField;
288
    ClientDataSetFeedsENc: TFloatField;
289
    ClientDataSetFeedsdEt: TFloatField;
290
    ClientDataSetFeedsEDt: TFloatField;
291
    ClientDataSetFeedsEMt_EDt: TFloatField;
292
    ClientDataSetFeedsEMt: TFloatField;
293
    ClientDataSetFeedsENt_EMt: TFloatField;
294
    ClientDataSetFeedsENt: TFloatField;
295
    ClientDataSetFeedsEDt_EDc: TFloatField;
296
    ClientDataSetFeedsEMt_EMc: TFloatField;
297
    ClientDataSetFeedsENt_ENc: TFloatField;
298
    ClientDataSetFeedsdNc: TFloatField;
299
    ClientDataSetFeedsdNt: TFloatField;
300
    ClientDataSetFeedsLys: TFloatField;
301
    ClientDataSetFeedsThr: TFloatField;
302
    ClientDataSetFeedsMet: TFloatField;
303
    ClientDataSetFeedsCys: TFloatField;
304
    ClientDataSetFeedsMetCys: TFloatField;
305
    ClientDataSetFeedsTrp: TFloatField;
306
    ClientDataSetFeedsIle: TFloatField;
307
    ClientDataSetFeedsVal: TFloatField;
308
    ClientDataSetFeedsLeu: TFloatField;
309
    ClientDataSetFeedsPhe: TFloatField;
310
    ClientDataSetFeedsTyr: TFloatField;
311
    ClientDataSetFeedsPheTyr: TFloatField;
312
    ClientDataSetFeedsHis: TFloatField;
313
    ClientDataSetFeedsArg: TFloatField;
314
    ClientDataSetFeedsAla: TFloatField;
315
    ClientDataSetFeedsAsp: TFloatField;
316
    ClientDataSetFeedsGlu: TFloatField;
317
    ClientDataSetFeedsGly: TFloatField;
318
    ClientDataSetFeedsSer: TFloatField;
319
    ClientDataSetFeedsPro: TFloatField;
320
    ClientDataSetFeedsLysd: TFloatField;
321
    ClientDataSetFeedsThrd: TFloatField;
322
    ClientDataSetFeedsMetd: TFloatField;
323
    ClientDataSetFeedsCysd: TFloatField;
324
    ClientDataSetFeedsMetCysd: TFloatField;
325
    ClientDataSetFeedsTrpd: TFloatField;
326
    ClientDataSetFeedsIled: TFloatField;
327
    ClientDataSetFeedsVald: TFloatField;
328
    ClientDataSetFeedsLeud: TFloatField;
329
    ClientDataSetFeedsPhed: TFloatField;
330
    ClientDataSetFeedsTyrd: TFloatField;
331
    ClientDataSetFeedsPheTyrd: TFloatField;
332
    ClientDataSetFeedsHisd: TFloatField;
333
    ClientDataSetFeedsArgd: TFloatField;
334
    ClientDataSetFeedsAlad: TFloatField;
335
    ClientDataSetFeedsAspd: TFloatField;
336
    ClientDataSetFeedsGlud: TFloatField;
337
    ClientDataSetFeedsGlyd: TFloatField;
338
    ClientDataSetFeedsSerd: TFloatField;
339
    ClientDataSetFeedsProd: TFloatField;
340
    ClientDataSetFeedsLysd_ENc: TFloatField;
341
    ClientDataSetFeedsLysd_ENt: TFloatField;
342
    ClientDataSetFeedsThrd_Lysd: TFloatField;
343
    ClientDataSetFeedsMetd_Lysd: TFloatField;
344
    ClientDataSetFeedsCysd_Lysd: TFloatField;
345
    ClientDataSetFeedsMetCysd_Lysd: TFloatField;
346
    ClientDataSetFeedsTrpd_Lysd: TFloatField;
347
    ClientDataSetFeedsIled_Lysd: TFloatField;
348
    ClientDataSetFeedsVald_Lysd: TFloatField;
349
    ClientDataSetFeedsLeud_Lysd: TFloatField;
350
    ClientDataSetFeedsPhed_Lysd: TFloatField;
351
    ClientDataSetFeedsTyrd_Lysd: TFloatField;
352
    ClientDataSetFeedsPheTyrd_Lysd: TFloatField;
353
    ClientDataSetFeedsHisd_Lysd: TFloatField;
354
    ClientDataSetFeedsArgd_Lysd: TFloatField;
355
    ClientDataSetFeedsAlad_Lysd: TFloatField;
356
    ClientDataSetFeedsAspd_Lysd: TFloatField;
357
    ClientDataSetFeedsGlud_Lysd: TFloatField;
358
    ClientDataSetFeedsGlyd_Lysd: TFloatField;
359
    ClientDataSetFeedsSerd_Lysd: TFloatField;
360
    ClientDataSetFeedsProd_Lysd: TFloatField;
361
    ClientDataSetFeedsCa: TFloatField;
362
    ClientDataSetFeedsP: TFloatField;
363
    ClientDataSetFeedsPd: TFloatField;
364
    ClientDataSetFeedsCa_Pd: TFloatField;
365
    ClientDataSetFeedsPd_ENc: TFloatField;
366
    ClientDataSetFeedsPd_ENt: TFloatField;
367
    ClientDataSetFeedsPhytaseId: TIntegerField;
368
    ClientDataSetFeedsPhytaseType: TFloatField;
369
    ClientDataSetFeedsPhytaseConcentration: TFloatField;
370
    ClientDataSetFeedsPhytaseIncorporation: TFloatField;
371
    ClientDataSetFeedsPhytaseLevel: TFloatField;
372
    ClientDataSetFeedsLevelSum: TFloatField;
373
    ClientDataSetFeedsTotal: TFloatField;
374
    ClientDataSetFeedsRemain: TFloatField;
375
    ClientDataSetFeedsNa: TFloatField;
376
    ClientDataSetFeedsK: TFloatField;
377
    ClientDataSetFeedsCl: TFloatField;
378
    ClientDataSetFeedsBE: TFloatField;
379
    DataSourceFeeds: TDataSource;
380
    procedure DataModuleCreate(Sender: TObject);
381
    procedure DataModuleDestroy(Sender: TObject);
382
    procedure ClientDataSetIngredientsFilterRecord(DataSet: TDataSet; var Accept: Boolean);
383
    procedure ClientDataSetFeedsCalcFields(DataSet: TDataSet);
384
    procedure AggregateLevelSumUpdate(Agg: TAggregate);
385
  private
386
    { D?clarations priv?es }
387
  public
388
    { D?clarations publiques }
389
    DBUser: TSQLiteDatabase;
390
    TableIngredients: TSQLiteTable;
391
    TableFeeds: TSQLiteTable;
392
    TableComposition: TSQLiteTable;
393
    RapMS, RapMAT: Double;
394
    ClassList, UserList, FeedList: TStrings;
395
    FilterOnClass, FilterOnDatabase, FilterOnName: Boolean;
396
    FilteredClass, FilteredDatabase: Integer;
397
    FilteredName: String;
398
    procedure CalcInraAfz;
399
    procedure CalcOriginal;
400
    procedure CalcCopy;
401
    procedure CalcFeed;
402
    function CalcBilanElectrolytique(Na, K, Cl: Double): Double;
403
    function InputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
404
    function InputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
405
    function InputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
406
    function InputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
407
    function InputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
408
    function OutputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
409
    function OutputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
410
    function OutputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
411
    function OutputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
412
    function OutputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
413
    function StrTrunc(S: String; Max: Integer): String;
414
  end;
415

    
416
var
417
  DataModuleDeclaration: TDataModuleDeclaration;
418
  MajorVersion, MinorVersion, ReleaseVersion, BuildVersion: Integer ;
419

    
420
implementation
421

    
422
{$R *.dfm}
423

    
424
uses
425
  SHFolder, StrUtils, UnitOptions;
426

    
427
procedure TDataModuleDeclaration.AggregateLevelSumUpdate(Agg: TAggregate);
428
begin
429
  if not ClientDataSetFeeds.Eof
430
  then
431
  begin
432
    ClientDataSetFeeds.Edit;
433
    if VarIsEmpty(Agg.Value) or VarIsNull(Agg.Value)
434
    then
435
      ClientDataSetFeedsLevelSum.Clear
436
    else
437
      ClientDataSetFeedsLevelSum.AsFloat := Agg.Value;
438
    ClientDataSetFeeds.Post;
439
  end;
440
end;
441

    
442
procedure TDataModuleDeclaration.ClientDataSetFeedsCalcFields(DataSet: TDataSet);
443
begin
444
  if ClientDataSetFeedsPhytaseIncorporation.IsNull or ClientDataSetFeedsPhytaseConcentration.IsNull
445
  or (ClientDataSetFeedsPhytaseConcentration.Value = 0)
446
  then
447
    ClientDataSetFeedsPhytaseLevel.Clear
448
  else
449
    ClientDataSetFeedsPhytaseLevel.Value := OutputIncorporation(ClientDataSetFeedsPhytaseIncorporation.Value / ClientDataSetFeedsPhytaseConcentration.Value / 1000, FormOptions.Incorporation);
450
  ClientDataSetFeedsTotal.Value := ClientDataSetFeedsLevelSum.Value + ClientDataSetFeedsPhytaseLevel.Value;
451
  ClientDataSetFeedsRemain.Value := OutputIncorporation(1, FormOptions.Incorporation) - ClientDataSetFeedsTotal.Value;
452
end;
453

    
454
procedure TDataModuleDeclaration.ClientDataSetIngredientsFilterRecord(DataSet: TDataSet; var Accept: Boolean);
455
begin
456
  Accept := True;
457
  if FilterOnClass and (FilteredClass > 0)
458
  then
459
    Accept := Accept and (DataSet.FieldByName('Class').AsInteger = FilteredClass);
460
  if FilterOnDatabase
461
  then
462
    case FilteredDatabase of
463
      1: // User database
464
        Accept := Accept and DataSet.FieldByName('User').AsBoolean;
465
      2: // Reference tables
466
        Accept := Accept and not DataSet.FieldByName('User').AsBoolean;
467
    end;
468
  if FilterOnName and (FilteredName <> '')
469
  then
470
    Accept := Accept and (Pos(FilteredName, DataSet.FieldByName('Name').AsWideString) > 0);
471
end;
472

    
473
procedure TDataModuleDeclaration.DataModuleCreate(Sender: TObject);
474
var
475
  i: Integer;
476
  ExeDir, DataDir, DataFile: String;
477
  Cryptage: TLbBlowfish;
478
  FluxClair, FluxCrypte: TMemoryStream;
479
  DocumentsPath: array[0..MAX_PATH] of Char;
480
begin
481
  // Classes
482
  ClassList := TStringList.Create;
483
  ClassList.Add('Cereals');
484
  ClassList.Add('Wheat by-products');
485
  ClassList.Add('Maize by-products');
486
  ClassList.Add('Other cereal by-products');
487
  ClassList.Add('Rice by-products');
488
  ClassList.Add('Legume and oil seeds');
489
  ClassList.Add('Oil seed meals');
490
  ClassList.Add('Starch, roots and tubers');
491
  ClassList.Add('Fruits and vegetables by-products');
492
  ClassList.Add('Molasses and vinasses');
493
  ClassList.Add('Other plant products');
494
  ClassList.Add('Dehydrated forages');
495
  ClassList.Add('Dairy products');
496
  ClassList.Add('Fish meals and solubles');
497
  ClassList.Add('Other animal by-products');
498
  ClassList.Add('Fats and oils');
499
  ClassList.Add('Amino acids');
500
  ClassList.Add('Mineral sources');
501
  ClassList.Add('Not referenced');
502
  ClientDataSetClasses.CreateDataSet;
503
  for i := 0 to ClassList.Count - 1 do
504
    ClientDataSetClasses.AppendRecord([i + 1, dgettext('InraAfz', ClassList[i])]);
505
  // Phytase
506
  ClientDataSetPhytase.CreateDataSet;
507
  ClientDataSetPhytase.AppendRecord([1, 0.60, 0.67]);
508
  ClientDataSetPhytase.AppendRecord([2, 0.65, 0.76]);
509
  ClientDataSetPhytase.AppendRecord([3, 0.70, 0.87]);
510
  ClientDataSetPhytase.AppendRecord([4, 0.75, 1.00]);
511
  ClientDataSetPhytase.AppendRecord([5, 0.80, 1.15]);
512
  ClientDataSetPhytase.AppendRecord([6, 0.85, 1.34]);
513
  ClientDataSetPhytase.AppendRecord([7, 0.90, 1.60]);
514
  ClientDataSetPhytase.AppendRecord([8, 0.95, 1.98]);
515
  // Tables de r?f?rence
516
  ExeDir := ExtractFilePath(Application.ExeName);
517
  DataFile := ExeDir + 'EvaPig2020.dat';
518
  if not FileExists(DataFile)
519
  then // Erreur
520
  begin
521
    MessageDlg(_('Reference tables of composition and nutritional values of feed materials for pigs') + sLineBreak
522
      + Format(_('%s: file not found'), [DataFile]), mtError, [mbOK], 0);
523
    Application.Terminate;
524
    Exit;
525
  end;
526
  ClientDataSetInraAfz.CreateDataSet;
527
  Cryptage := TlbBlowfish.Create(nil);
528
  Cryptage.GenerateKey('Tables of Composition and Nutritional Value of Feed Materials');
529
  FluxCrypte := TMemoryStream.Create;
530
  FluxClair := TMemoryStream.Create;
531
  try
532
    FluxCrypte.LoadFromFile(DataFile);
533
    FluxCrypte.Position := 0;
534
    Cryptage.DecryptStream(FluxCrypte, FluxClair);
535
    FluxClair.Position := 0;
536
    try
537
      ClientDataSetInraAfz.LoadFromStream(FluxClair);
538
    except
539
      MessageDlg(_('Reference tables of composition and nutritional values of feed materials for pigs') + sLineBreak
540
        + _('Invalid data format'), mtError, [mbOK], 0);
541
      Application.Terminate;
542
      Exit;
543
    end;
544
  finally
545
    FluxCrypte.Free;
546
    FluxClair.Free;
547
    Cryptage.Free;
548
  end;
549
  // Base User.sqb
550
  SHGetFolderPath(0, CSIDL_PERSONAL, 0, SHGFP_TYPE_CURRENT, DocumentsPath);
551
  DataDir := IncludeTrailingPathDelimiter(IncludeTrailingPathDelimiter(DocumentsPath) + Application.Title);
552
  ForceDirectories(DataDir);
553
  if not FileExists(ExeDir + 'sqlite3.dll')
554
  then // Erreur
555
  begin
556
    MessageDlg(_('SQLite') + sLineBreak
557
      + Format(_('%s: driver missing'), [ExeDir + 'sqlite3.dll']), mtError, [mbOK], 0);
558
    Application.Terminate;
559
    Exit;
560
  end;
561
  DBUser := TSQLiteDatabase.Create(DataDir + 'User.sqb');
562
  if not DBUser.TableExists('Ingredients')
563
  then // Cr?ation de la table Ingredients
564
  begin
565
    DBUser.ExecSQL('CREATE TABLE Ingredients ('
566
      + 'Id INTEGER PRIMARY KEY, '
567
      + 'Name TEXT, '
568
      + 'Definition TEXT, '
569
      + 'Class INTEGER, '
570
      + 'Model INTEGER, '
571
      + 'MS REAL, '
572
      + 'MM REAL, '
573
      + 'MAT REAL, '
574
      + 'MG REAL, '
575
      + 'CB REAL, '
576
      + 'NDF REAL, '
577
      + 'ADF REAL, '
578
      + 'ADL REAL, '
579
      + 'Amidon REAL, '
580
      + 'Sucres REAL, '
581
      + 'EB REAL, '
582
      + 'Bonus REAL, '
583
      + 'Lys REAL, '
584
      + 'Thr REAL, '
585
      + 'Met REAL, '
586
      + 'Cys REAL, '
587
      + 'MetCys REAL, '
588
      + 'Trp REAL, '
589
      + 'Ile REAL, '
590
      + 'Val REAL, '
591
      + 'Leu REAL, '
592
      + 'Phe REAL, '
593
      + 'Tyr REAL, '
594
      + 'PheTyr REAL, '
595
      + 'His REAL, '
596
      + 'Arg REAL, '
597
      + 'Ala REAL, '
598
      + 'Asp REAL, '
599
      + 'Glu REAL, '
600
      + 'Gly REAL, '
601
      + 'Ser REAL, '
602
      + 'Pro REAL, '
603
      + 'dLys REAL, '
604
      + 'dThr REAL, '
605
      + 'dMet REAL, '
606
      + 'dCys REAL, '
607
      + 'dMetCys REAL, '
608
      + 'dTrp REAL, '
609
      + 'dIle REAL, '
610
      + 'dVal REAL, '
611
      + 'dLeu REAL, '
612
      + 'dPhe REAL, '
613
      + 'dTyr REAL, '
614
      + 'dPheTyr REAL, '
615
      + 'dHis REAL, '
616
      + 'dArg REAL, '
617
      + 'dAla REAL, '
618
      + 'dAsp REAL, '
619
      + 'dGlu REAL, '
620
      + 'dGly REAL, '
621
      + 'dSer REAL, '
622
      + 'dPro REAL, '
623
      + 'Ca REAL, '
624
      + 'P REAL, '
625
      + 'Na REAL, '
626
      + 'K REAL, '
627
      + 'Cl REAL, '
628
      + 'dP REAL, '
629
      + 'dPphy REAL)');
630
    DBUser.ExecSQL('CREATE INDEX IdxClasses ON Ingredients (Class)');
631
    DBUser.ExecSQL('CREATE INDEX IdxModels ON Ingredients (Model)');
632
  end;
633
  if not DBUser.TableExists('Feeds')
634
  then // Cr?ation de la table Feeds
635
    DBUser.ExecSQL('CREATE TABLE Feeds ('
636
      + 'Id INTEGER PRIMARY KEY, '
637
      + 'Name TEXT, '
638
      + 'Description TEXT, '
639
      + 'Presentation INTEGER, '
640
      + 'BonusC REAL, '
641
      + 'BonusT REAL, '
642
      + 'Phytase INTEGER, '
643
      + 'Concentration REAL, '
644
      + 'Incorporation REAL)');
645
  if not DBUser.TableExists('Composition')
646
  then // Cr?ation de la table Composition
647
  begin
648
    DBUser.ExecSQL('CREATE TABLE Composition ('
649
      + 'Feed INTEGER, '
650
      + 'Ingredient INTEGER, '
651
      + 'User BOOLEAN, '
652
      + 'Rank INTEGER, '
653
      + 'MS REAL, '
654
      + 'Level REAL)');
655
    DBUser.ExecSQL('CREATE INDEX IdxFeeds ON Composition (Feed)');
656
    DBUser.ExecSQL('CREATE INDEX IdxIngredients ON Composition (Ingredient)');
657
  end;
658
  Application.ProcessMessages;
659
  // Liste des mati?res premi?res utilisateur
660
  UserList := TStringList.Create;
661
  TableIngredients := DBUser.GetTable('SELECT Name FROM Ingredients');
662
  with TableIngredients do
663
    try
664
      while not Eof do
665
      begin
666
        UserList.Add(FieldAsString(FieldIndex['Name']));
667
        Next;
668
      end;
669
    finally
670
      Free;
671
    end;
672
  // Liste des r?gimes
673
  FeedList := TStringList.Create;
674
  TableFeeds := DBUser.GetTable('SELECT Name FROM Feeds');
675
  with TableFeeds do
676
    try
677
      while not Eof do
678
      begin
679
        FeedList.Add(FieldAsString(FieldIndex['Name']));
680
        Next;
681
      end;
682
    finally
683
      Free;
684
    end;
685
end;
686

    
687
procedure TDataModuleDeclaration.DataModuleDestroy(Sender: TObject);
688
begin
689
  ClientDataSetClasses.Close;
690
  ClientDataSetPhytase.Close;
691
  ClientDataSetInraAfz.Close;
692
  ClassList.Free;
693
  UserList.Free;
694
  FeedList.Free;
695
  Application.ProcessMessages;
696
  DBUser.ExecSQL('VACUUM'); // Compacter la base User.sqb
697
  DBUser.Free;
698
  Application.ProcessMessages;
699
end;
700

    
701
procedure TDataModuleDeclaration.CalcInraAfz;
702
// Renseigner l'enregistrement courant de ClientDataSetIngredients
703
// ? partir de l'enregistrement courant de ClientDataSetInraAfz
704
// en tenant compte des unit?s configur?es
705
begin
706
  // Analyse proximale
707
  RapMS := ClientDataSetInraAfzMS.Value;
708
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
709
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
710
  ClientDataSetIngredientsMM.Value := OutputProximal(ClientDataSetInraAfzMM.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
711
  RapMAT := ClientDataSetInraAfzMAT.Value;
712
  ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
713
  ClientDataSetIngredientsMG.Value := OutputProximal(ClientDataSetInraAfzMG.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
714
  ClientDataSetIngredientsCB.Value := OutputProximal(ClientDataSetInraAfzCB.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
715
  ClientDataSetIngredientsNDF.Value := OutputProximal(ClientDataSetInraAfzNDF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
716
  ClientDataSetIngredientsADF.Value := OutputProximal(ClientDataSetInraAfzADF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
717
  ClientDataSetIngredientsADL.Value := OutputProximal(ClientDataSetInraAfzADL.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
718
  ClientDataSetIngredientsAmidon.Value := OutputProximal(ClientDataSetInraAfzAmidon.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
719
  ClientDataSetIngredientsSucres.Value := OutputProximal(ClientDataSetInraAfzSucres.Value, RapMS, FormOptions.Expression, FormOptions.Proximal);
720
  // Energie
721
  ClientDataSetIngredientsEB.Value := OutputEnergy(ClientDataSetInraAfzEB.Value, RapMS, FormOptions.Expression, FormOptions.Energy);
722
  ClientDataSetIngredientsBonus.Value := 0;
723
  if ClientDataSetIngredientsEB.Value = 0
724
  then
725
    ClientDataSetIngredientsdEt.Clear
726
  else
727
    ClientDataSetIngredientsdEc.Value := ClientDataSetInraAfzdEc.Value * 100;
728
  ClientDataSetIngredientsEDc.Value := ClientDataSetIngredientsEB.Value * ClientDataSetIngredientsdEc.Value / 100;
729
  if ClientDataSetIngredientsEDc.Value = 0
730
  then
731
    ClientDataSetIngredientsEMc_EDc.Clear
732
  else
733
    ClientDataSetIngredientsEMc_EDc.Value := ClientDataSetInraAfzEMc_EDc.Value * 100;
734
  ClientDataSetIngredientsEMc.Value := ClientDataSetIngredientsEDc.Value * ClientDataSetIngredientsEMc_EDc.Value / 100;
735
  if ClientDataSetIngredientsEMc.Value = 0
736
  then
737
    ClientDataSetIngredientsENc_EMc.Clear
738
  else
739
    ClientDataSetIngredientsENc_EMc.Value := ClientDataSetInraAfzENc_EMc.Value * 100;
740
  ClientDataSetIngredientsENc.Value := ClientDataSetIngredientsEMc.Value * ClientDataSetIngredientsENc_EMc.Value / 100;
741
  if ClientDataSetIngredientsEDc.Value = 0
742
  then
743
    ClientDataSetIngredientsEDt_EDc.Clear
744
  else
745
    ClientDataSetIngredientsEDt_EDc.Value := ClientDataSetInraAfzEDt_EDc.Value * 100;
746
  ClientDataSetIngredientsEDt.Value := ClientDataSetIngredientsEDc.Value * ClientDataSetIngredientsEDt_EDc.Value / 100;
747
  if ClientDataSetIngredientsEDt.Value = 0
748
  then
749
    ClientDataSetIngredientsEMt_EDt.Clear
750
  else
751
    ClientDataSetIngredientsEMt_EDt.Value := ClientDataSetInraAfzEMt_EDt.Value * 100;
752
  ClientDataSetIngredientsEMt.Value := ClientDataSetIngredientsEDt.Value * ClientDataSetIngredientsEMt_EDt.Value / 100;
753
  if ClientDataSetIngredientsEMt.Value = 0
754
  then
755
    ClientDataSetIngredientsENt_EMt.Clear
756
  else
757
    ClientDataSetIngredientsENt_EMt.Value := ClientDataSetInraAfzENt_EMt.Value * 100;
758
  ClientDataSetIngredientsENt.Value := ClientDataSetIngredientsEMt.Value * ClientDataSetIngredientsENt_EMt.Value / 100;
759
  if ClientDataSetIngredientsEB.Value = 0
760
  then
761
    ClientDataSetIngredientsdEt.Clear
762
  else
763
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
764
  if ClientDataSetIngredientsEMc.Value = 0
765
  then
766
    ClientDataSetIngredientsEMt_EMc.Clear
767
  else
768
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
769
  if ClientDataSetIngredientsENc.Value = 0
770
  then
771
    ClientDataSetIngredientsENt_ENc.Clear
772
  else
773
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
774
  // Digestibilit? f?cale de l'azote
775
  if RapMAT = 0
776
  then
777
    ClientDataSetIngredientsdNc.Clear
778
  else
779
    ClientDataSetIngredientsdNc.Value := ClientDataSetInraAfzdNc.Value * 100;
780
  if RapMAT = 0
781
  then
782
    ClientDataSetIngredientsdNt.Clear
783
  else
784
    ClientDataSetIngredientsdNt.Value := ClientDataSetInraAfzdNt.Value * 100;
785
  // Acides amin?s
786
  if RapMAT = 0
787
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
788
  begin
789
    // Teneurs
790
    ClientDataSetIngredientsLys.Value := 0;
791
    ClientDataSetIngredientsThr.Value := 0;
792
    ClientDataSetIngredientsMet.Value := 0;
793
    ClientDataSetIngredientsCys.Value := 0;
794
    ClientDataSetIngredientsMetCys.Value := 0;
795
    ClientDataSetIngredientsTrp.Value := 0;
796
    ClientDataSetIngredientsIle.Value := 0;
797
    ClientDataSetIngredientsVal.Value := 0;
798
    ClientDataSetIngredientsLeu.Value := 0;
799
    ClientDataSetIngredientsPhe.Value := 0;
800
    ClientDataSetIngredientsTyr.Value := 0;
801
    ClientDataSetIngredientsPheTyr.Value := 0;
802
    ClientDataSetIngredientsHis.Value := 0;
803
    ClientDataSetIngredientsArg.Value := 0;
804
    ClientDataSetIngredientsAla.Value := 0;
805
    ClientDataSetIngredientsAsp.Value := 0;
806
    ClientDataSetIngredientsGlu.Value := 0;
807
    ClientDataSetIngredientsGly.Value := 0;
808
    ClientDataSetIngredientsSer.Value := 0;
809
    ClientDataSetIngredientsPro.Value := 0;
810
    // % MAT
811
    ClientDataSetIngredientsLys_MAT.Clear;
812
    ClientDataSetIngredientsThr_MAT.Clear;
813
    ClientDataSetIngredientsMet_MAT.Clear;
814
    ClientDataSetIngredientsCys_MAT.Clear;
815
    ClientDataSetIngredientsMetCys_MAT.Clear;
816
    ClientDataSetIngredientsTrp_MAT.Clear;
817
    ClientDataSetIngredientsIle_MAT.Clear;
818
    ClientDataSetIngredientsVal_MAT.Clear;
819
    ClientDataSetIngredientsLeu_MAT.Clear;
820
    ClientDataSetIngredientsPhe_MAT.Clear;
821
    ClientDataSetIngredientsTyr_MAT.Clear;
822
    ClientDataSetIngredientsPheTyr_MAT.Clear;
823
    ClientDataSetIngredientsHis_MAT.Clear;
824
    ClientDataSetIngredientsArg_MAT.Clear;
825
    ClientDataSetIngredientsAla_MAT.Clear;
826
    ClientDataSetIngredientsAsp_MAT.Clear;
827
    ClientDataSetIngredientsGlu_MAT.Clear;
828
    ClientDataSetIngredientsGly_MAT.Clear;
829
    ClientDataSetIngredientsSer_MAT.Clear;
830
    ClientDataSetIngredientsPro_MAT.Clear;
831
    // Digestibilit?s
832
    ClientDataSetIngredientsdLys.Clear;
833
    ClientDataSetIngredientsdThr.Clear;
834
    ClientDataSetIngredientsdMet.Clear;
835
    ClientDataSetIngredientsdCys.Clear;
836
    ClientDataSetIngredientsdMetCys.Clear;
837
    ClientDataSetIngredientsdTrp.Clear;
838
    ClientDataSetIngredientsdIle.Clear;
839
    ClientDataSetIngredientsdVal.Clear;
840
    ClientDataSetIngredientsdLeu.Clear;
841
    ClientDataSetIngredientsdPhe.Clear;
842
    ClientDataSetIngredientsdTyr.Clear;
843
    ClientDataSetIngredientsdPheTyr.Clear;
844
    ClientDataSetIngredientsdHis.Clear;
845
    ClientDataSetIngredientsdArg.Clear;
846
    ClientDataSetIngredientsdAla.Clear;
847
    ClientDataSetIngredientsdAsp.Clear;
848
    ClientDataSetIngredientsdGlu.Clear;
849
    ClientDataSetIngredientsdGly.Clear;
850
    ClientDataSetIngredientsdSer.Clear;
851
    ClientDataSetIngredientsdPro.Clear;
852
    // Teneurs digestibles
853
    ClientDataSetIngredientsLysd.Value := 0;
854
    ClientDataSetIngredientsThrd.Value := 0;
855
    ClientDataSetIngredientsMetd.Value := 0;
856
    ClientDataSetIngredientsCysd.Value := 0;
857
    ClientDataSetIngredientsMetCysd.Value := 0;
858
    ClientDataSetIngredientsTrpd.Value := 0;
859
    ClientDataSetIngredientsIled.Value := 0;
860
    ClientDataSetIngredientsVald.Value := 0;
861
    ClientDataSetIngredientsLeud.Value := 0;
862
    ClientDataSetIngredientsPhed.Value := 0;
863
    ClientDataSetIngredientsTyrd.Value := 0;
864
    ClientDataSetIngredientsPheTyrd.Value := 0;
865
    ClientDataSetIngredientsHisd.Value := 0;
866
    ClientDataSetIngredientsArgd.Value := 0;
867
    ClientDataSetIngredientsAlad.Value := 0;
868
    ClientDataSetIngredientsAspd.Value := 0;
869
    ClientDataSetIngredientsGlud.Value := 0;
870
    ClientDataSetIngredientsGlyd.Value := 0;
871
    ClientDataSetIngredientsSerd.Value := 0;
872
    ClientDataSetIngredientsProd.Value := 0;
873
  end
874
  else
875
  begin
876
    // Lys
877
    if ClientDataSetInraAfzLys.Value = 0
878
    then
879
    begin
880
      ClientDataSetIngredientsLys.Value := 0;
881
      ClientDataSetIngredientsLys_MAT.Clear;
882
      ClientDataSetIngredientsdLys.Clear;
883
      ClientDataSetIngredientsLysd.Value := 0;
884
    end
885
    else
886
    begin
887
      ClientDataSetIngredientsLys.Value := OutputAA(ClientDataSetInraAfzLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
888
      if ClientDataSetIngredientsLys.Value = 0
889
      then
890
        ClientDataSetIngredientsLys_MAT.Clear
891
      else
892
        ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
893
      if ClientDataSetInraAfzdLys.IsNull
894
      then
895
        ClientDataSetIngredientsdLys.Value := dLys * 100
896
      else
897
        ClientDataSetIngredientsdLys.Value := ClientDataSetInraAfzdLys.Value * 100;
898
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value / 100 * ClientDataSetIngredientsLys.Value;
899
    end;
900
    // Thr
901
    if ClientDataSetInraAfzThr.Value = 0
902
    then
903
    begin
904
      ClientDataSetIngredientsThr.Value := 0;
905
      ClientDataSetIngredientsThr_MAT.Clear;
906
      ClientDataSetIngredientsdThr.Clear;
907
      ClientDataSetIngredientsThrd.Value := 0;
908
    end
909
    else
910
    begin
911
      ClientDataSetIngredientsThr.Value := OutputAA(ClientDataSetInraAfzThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
912
      if ClientDataSetIngredientsThr.Value = 0
913
      then
914
        ClientDataSetIngredientsThr_MAT.Clear
915
      else
916
        ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
917
      if ClientDataSetInraAfzdThr.IsNull
918
      then
919
        ClientDataSetIngredientsdThr.Value := dThr * 100
920
      else
921
        ClientDataSetIngredientsdThr.Value := ClientDataSetInraAfzdThr.Value * 100;
922
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value / 100 * ClientDataSetIngredientsThr.Value;
923
    end;
924
    // Met
925
    if ClientDataSetInraAfzMet.Value = 0
926
    then
927
    begin
928
      ClientDataSetIngredientsMet.Value := 0;
929
      ClientDataSetIngredientsMet_MAT.Clear;
930
      ClientDataSetIngredientsdMet.Clear;
931
      ClientDataSetIngredientsMetd.Value := 0;
932
    end
933
    else
934
    begin
935
      ClientDataSetIngredientsMet.Value := OutputAA(ClientDataSetInraAfzMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
936
      if ClientDataSetIngredientsMet.Value = 0
937
      then
938
        ClientDataSetIngredientsMet_MAT.Clear
939
      else
940
        ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
941
      if ClientDataSetInraAfzdMet.IsNull
942
      then
943
        ClientDataSetIngredientsdMet.Value := dMet * 100
944
      else
945
        ClientDataSetIngredientsdMet.Value := ClientDataSetInraAfzdMet.Value * 100;
946
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value / 100 * ClientDataSetIngredientsMet.Value;
947
    end;
948
    // Cys
949
    if ClientDataSetInraAfzCys.Value = 0
950
    then
951
    begin
952
      ClientDataSetIngredientsCys.Value := 0;
953
      ClientDataSetIngredientsCys_MAT.Clear;
954
      ClientDataSetIngredientsdCys.Clear;
955
      ClientDataSetIngredientsCysd.Value := 0;
956
    end
957
    else
958
    begin
959
      ClientDataSetIngredientsCys.Value := OutputAA(ClientDataSetInraAfzCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
960
      if ClientDataSetIngredientsCys.Value = 0
961
      then
962
        ClientDataSetIngredientsCys_MAT.Clear
963
      else
964
        ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
965
      if ClientDataSetInraAfzdCys.IsNull
966
      then
967
        ClientDataSetIngredientsdCys.Value := dCys * 100
968
      else
969
        ClientDataSetIngredientsdCys.Value := ClientDataSetInraAfzdCys.Value * 100;
970
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value / 100 * ClientDataSetIngredientsCys.Value;
971
    end;
972
    // Met + Cys
973
    if ClientDataSetInraAfzMetCys.Value = 0
974
    then
975
    begin
976
      ClientDataSetIngredientsMetCys.Value := 0;
977
      ClientDataSetIngredientsMetCys_MAT.Clear;
978
      ClientDataSetIngredientsdMetCys.Clear;
979
      ClientDataSetIngredientsMetCysd.Value := 0;
980
    end
981
    else
982
    begin
983
      ClientDataSetIngredientsMetCys.Value := OutputAA(ClientDataSetInraAfzMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
984
      if ClientDataSetIngredientsMetCys.Value = 0
985
      then
986
        ClientDataSetIngredientsMetCys_MAT.Clear
987
      else
988
        ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
989
      if ClientDataSetInraAfzdMetCys.IsNull
990
      then
991
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
992
      else
993
        ClientDataSetIngredientsdMetCys.Value := ClientDataSetInraAfzdMetCys.Value * 100;
994
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value / 100 * ClientDataSetIngredientsMetCys.Value;
995
    end;
996
    // Trp
997
    if ClientDataSetInraAfzTrp.Value = 0
998
    then
999
    begin
1000
      ClientDataSetIngredientsTrp.Value := 0;
1001
      ClientDataSetIngredientsTrp_MAT.Clear;
1002
      ClientDataSetIngredientsdTrp.Clear;
1003
      ClientDataSetIngredientsTrpd.Value := 0;
1004
    end
1005
    else
1006
    begin
1007
      ClientDataSetIngredientsTrp.Value := OutputAA(ClientDataSetInraAfzTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1008
      if ClientDataSetIngredientsTrp.Value = 0
1009
      then
1010
        ClientDataSetIngredientsTrp_MAT.Clear
1011
      else
1012
        ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1013
      if ClientDataSetInraAfzdTrp.IsNull
1014
      then
1015
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
1016
      else
1017
        ClientDataSetIngredientsdTrp.Value := ClientDataSetInraAfzdTrp.Value * 100;
1018
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value / 100 * ClientDataSetIngredientsTrp.Value;
1019
    end;
1020
    // Ile
1021
    if ClientDataSetInraAfzIle.Value = 0
1022
    then
1023
    begin
1024
      ClientDataSetIngredientsIle.Value := 0;
1025
      ClientDataSetIngredientsIle_MAT.Clear;
1026
      ClientDataSetIngredientsdIle.Clear;
1027
      ClientDataSetIngredientsIled.Value := 0;
1028
    end
1029
    else
1030
    begin
1031
      ClientDataSetIngredientsIle.Value := OutputAA(ClientDataSetInraAfzIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1032
      if ClientDataSetIngredientsIle.Value = 0
1033
      then
1034
        ClientDataSetIngredientsIle_MAT.Clear
1035
      else
1036
        ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1037
      if ClientDataSetInraAfzdIle.IsNull
1038
      then
1039
        ClientDataSetIngredientsdIle.Value := dIle * 100
1040
      else
1041
        ClientDataSetIngredientsdIle.Value := ClientDataSetInraAfzdIle.Value * 100;
1042
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value / 100 * ClientDataSetIngredientsIle.Value;
1043
    end;
1044
    // Val
1045
    if ClientDataSetInraAfzVal.Value = 0
1046
    then
1047
    begin
1048
      ClientDataSetIngredientsVal.Value := 0;
1049
      ClientDataSetIngredientsVal_MAT.Clear;
1050
      ClientDataSetIngredientsdVal.Clear;
1051
      ClientDataSetIngredientsVald.Value := 0;
1052
    end
1053
    else
1054
    begin
1055
      ClientDataSetIngredientsVal.Value := OutputAA(ClientDataSetInraAfzVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1056
      if ClientDataSetIngredientsVal.Value = 0
1057
      then
1058
        ClientDataSetIngredientsVal_MAT.Clear
1059
      else
1060
        ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1061
      if ClientDataSetInraAfzdVal.IsNull
1062
      then
1063
        ClientDataSetIngredientsdVal.Value := dVal * 100
1064
      else
1065
        ClientDataSetIngredientsdVal.Value := ClientDataSetInraAfzdVal.Value * 100;
1066
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value / 100 * ClientDataSetIngredientsVal.Value;
1067
    end;
1068
    // Leu
1069
    if ClientDataSetInraAfzLeu.Value = 0
1070
    then
1071
    begin
1072
      ClientDataSetIngredientsLeu.Value := 0;
1073
      ClientDataSetIngredientsLeu_MAT.Clear;
1074
      ClientDataSetIngredientsdLeu.Clear;
1075
      ClientDataSetIngredientsLeud.Value := 0;
1076
    end
1077
    else
1078
    begin
1079
      ClientDataSetIngredientsLeu.Value := OutputAA(ClientDataSetInraAfzLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1080
      if ClientDataSetIngredientsLeu.Value = 0
1081
      then
1082
        ClientDataSetIngredientsLeu_MAT.Clear
1083
      else
1084
        ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1085
      if ClientDataSetInraAfzdLeu.IsNull
1086
      then
1087
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
1088
      else
1089
        ClientDataSetIngredientsdLeu.Value := ClientDataSetInraAfzdLeu.Value * 100;
1090
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value / 100 * ClientDataSetIngredientsLeu.Value;
1091
    end;
1092
    // Phe
1093
    if ClientDataSetInraAfzPhe.Value = 0
1094
    then
1095
    begin
1096
      ClientDataSetIngredientsPhe.Value := 0;
1097
      ClientDataSetIngredientsPhe_MAT.Clear;
1098
      ClientDataSetIngredientsdPhe.Clear;
1099
      ClientDataSetIngredientsPhed.Value := 0;
1100
    end
1101
    else
1102
    begin
1103
      ClientDataSetIngredientsPhe.Value := OutputAA(ClientDataSetInraAfzPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1104
      if ClientDataSetIngredientsPhe.Value = 0
1105
      then
1106
        ClientDataSetIngredientsPhe_MAT.Clear
1107
      else
1108
        ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1109
      if ClientDataSetInraAfzdPhe.IsNull
1110
      then
1111
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
1112
      else
1113
        ClientDataSetIngredientsdPhe.Value := ClientDataSetInraAfzdPhe.Value * 100;
1114
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value / 100 * ClientDataSetIngredientsPhe.Value;
1115
    end;
1116
    // Tyr
1117
    if ClientDataSetInraAfzTyr.Value = 0
1118
    then
1119
    begin
1120
      ClientDataSetIngredientsTyr.Value := 0;
1121
      ClientDataSetIngredientsTyr_MAT.Clear;
1122
      ClientDataSetIngredientsdTyr.Clear;
1123
      ClientDataSetIngredientsTyrd.Value := 0;
1124
    end
1125
    else
1126
    begin
1127
      ClientDataSetIngredientsTyr.Value := OutputAA(ClientDataSetInraAfzTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1128
      if ClientDataSetIngredientsTyr.Value = 0
1129
      then
1130
        ClientDataSetIngredientsTyr_MAT.Clear
1131
      else
1132
        ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1133
      if ClientDataSetInraAfzdTyr.IsNull
1134
      then
1135
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
1136
      else
1137
        ClientDataSetIngredientsdTyr.Value := ClientDataSetInraAfzdTyr.Value * 100;
1138
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value / 100 * ClientDataSetIngredientsTyr.Value;
1139
    end;
1140
    // Phe + Tyr
1141
    if ClientDataSetInraAfzPheTyr.Value = 0
1142
    then
1143
    begin
1144
      ClientDataSetIngredientsPheTyr.Value := 0;
1145
      ClientDataSetIngredientsPheTyr_MAT.Clear;
1146
      ClientDataSetIngredientsdPheTyr.Clear;
1147
      ClientDataSetIngredientsPheTyrd.Value := 0;
1148
    end
1149
    else
1150
    begin
1151
      ClientDataSetIngredientsPheTyr.Value := OutputAA(ClientDataSetInraAfzPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1152
      if ClientDataSetIngredientsPheTyr.Value = 0
1153
      then
1154
        ClientDataSetIngredientsPheTyr_MAT.Clear
1155
      else
1156
        ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1157
      if ClientDataSetInraAfzdPheTyr.IsNull
1158
      then
1159
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
1160
      else
1161
        ClientDataSetIngredientsdPheTyr.Value := ClientDataSetInraAfzdPheTyr.Value * 100;
1162
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value / 100 * ClientDataSetIngredientsPheTyr.Value;
1163
    end;
1164
    // His
1165
    if ClientDataSetInraAfzHis.Value = 0
1166
    then
1167
    begin
1168
      ClientDataSetIngredientsHis.Value := 0;
1169
      ClientDataSetIngredientsHis_MAT.Clear;
1170
      ClientDataSetIngredientsdHis.Clear;
1171
      ClientDataSetIngredientsHisd.Value := 0;
1172
    end
1173
    else
1174
    begin
1175
      ClientDataSetIngredientsHis.Value := OutputAA(ClientDataSetInraAfzHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1176
      if ClientDataSetIngredientsHis.Value = 0
1177
      then
1178
        ClientDataSetIngredientsHis_MAT.Clear
1179
      else
1180
        ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1181
      if ClientDataSetInraAfzdHis.IsNull
1182
      then
1183
        ClientDataSetIngredientsdHis.Value := dHis * 100
1184
      else
1185
        ClientDataSetIngredientsdHis.Value := ClientDataSetInraAfzdHis.Value * 100;
1186
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value / 100 * ClientDataSetIngredientsHis.Value;
1187
    end;
1188
    // Arg
1189
    if ClientDataSetInraAfzArg.Value = 0
1190
    then
1191
    begin
1192
      ClientDataSetIngredientsArg.Value := 0;
1193
      ClientDataSetIngredientsArg_MAT.Clear;
1194
      ClientDataSetIngredientsdArg.Clear;
1195
      ClientDataSetIngredientsArgd.Value := 0;
1196
    end
1197
    else
1198
    begin
1199
      ClientDataSetIngredientsArg.Value := OutputAA(ClientDataSetInraAfzArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1200
      if ClientDataSetIngredientsArg.Value = 0
1201
      then
1202
        ClientDataSetIngredientsArg_MAT.Clear
1203
      else
1204
        ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1205
      if ClientDataSetInraAfzdArg.IsNull
1206
      then
1207
        ClientDataSetIngredientsdArg.Value := dArg * 100
1208
      else
1209
        ClientDataSetIngredientsdArg.Value := ClientDataSetInraAfzdArg.Value * 100;
1210
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value / 100 * ClientDataSetIngredientsArg.Value;
1211
    end;
1212
    // Ala
1213
    if ClientDataSetInraAfzAla.Value = 0
1214
    then
1215
    begin
1216
      ClientDataSetIngredientsAla.Value := 0;
1217
      ClientDataSetIngredientsAla_MAT.Clear;
1218
      ClientDataSetIngredientsdAla.Clear;
1219
      ClientDataSetIngredientsAlad.Value := 0;
1220
    end
1221
    else
1222
    begin
1223
      ClientDataSetIngredientsAla.Value := OutputAA(ClientDataSetInraAfzAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1224
      if ClientDataSetIngredientsAla.Value = 0
1225
      then
1226
        ClientDataSetIngredientsAla_MAT.Clear
1227
      else
1228
        ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1229
      if ClientDataSetInraAfzdAla.IsNull
1230
      then
1231
        ClientDataSetIngredientsdAla.Value := dAla * 100
1232
      else
1233
        ClientDataSetIngredientsdAla.Value := ClientDataSetInraAfzdAla.Value * 100;
1234
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value / 100 * ClientDataSetIngredientsAla.Value;
1235
    end;
1236
    // Asp
1237
    if ClientDataSetInraAfzAsp.Value = 0
1238
    then
1239
    begin
1240
      ClientDataSetIngredientsAsp.Value := 0;
1241
      ClientDataSetIngredientsAsp_MAT.Clear;
1242
      ClientDataSetIngredientsdAsp.Clear;
1243
      ClientDataSetIngredientsAspd.Value := 0;
1244
    end
1245
    else
1246
    begin
1247
      ClientDataSetIngredientsAsp.Value := OutputAA(ClientDataSetInraAfzAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1248
      if ClientDataSetIngredientsAsp.Value = 0
1249
      then
1250
        ClientDataSetIngredientsAsp_MAT.Clear
1251
      else
1252
        ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1253
      if ClientDataSetInraAfzdAsp.IsNull
1254
      then
1255
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
1256
      else
1257
        ClientDataSetIngredientsdAsp.Value := ClientDataSetInraAfzdAsp.Value * 100;
1258
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value / 100 * ClientDataSetIngredientsAsp.Value;
1259
    end;
1260
    // Glu
1261
    if ClientDataSetInraAfzGlu.Value = 0
1262
    then
1263
    begin
1264
      ClientDataSetIngredientsGlu.Value := 0;
1265
      ClientDataSetIngredientsGlu_MAT.Clear;
1266
      ClientDataSetIngredientsdGlu.Clear;
1267
      ClientDataSetIngredientsGlud.Value := 0;
1268
    end
1269
    else
1270
    begin
1271
      ClientDataSetIngredientsGlu.Value := OutputAA(ClientDataSetInraAfzGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1272
      if ClientDataSetIngredientsGlu.Value = 0
1273
      then
1274
        ClientDataSetIngredientsGlu_MAT.Clear
1275
      else
1276
        ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1277
      if ClientDataSetInraAfzdGlu.IsNull
1278
      then
1279
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
1280
      else
1281
        ClientDataSetIngredientsdGlu.Value := ClientDataSetInraAfzdGlu.Value * 100;
1282
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value / 100 * ClientDataSetIngredientsGlu.Value;
1283
    end;
1284
    // Gly
1285
    if ClientDataSetInraAfzGly.Value = 0
1286
    then
1287
    begin
1288
      ClientDataSetIngredientsGly.Value := 0;
1289
      ClientDataSetIngredientsGly_MAT.Clear;
1290
      ClientDataSetIngredientsdGly.Clear;
1291
      ClientDataSetIngredientsGlyd.Value := 0;
1292
    end
1293
    else
1294
    begin
1295
      ClientDataSetIngredientsGly.Value := OutputAA(ClientDataSetInraAfzGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1296
      if ClientDataSetIngredientsGly.Value = 0
1297
      then
1298
        ClientDataSetIngredientsGly_MAT.Clear
1299
      else
1300
        ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1301
      if ClientDataSetInraAfzdGly.IsNull
1302
      then
1303
        ClientDataSetIngredientsdGly.Value := dGly * 100
1304
      else
1305
        ClientDataSetIngredientsdGly.Value := ClientDataSetInraAfzdGly.Value * 100;
1306
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value / 100 * ClientDataSetIngredientsGly.Value;
1307
    end;
1308
    // Ser
1309
    if ClientDataSetInraAfzSer.Value = 0
1310
    then
1311
    begin
1312
      ClientDataSetIngredientsSer.Value := 0;
1313
      ClientDataSetIngredientsSer_MAT.Clear;
1314
      ClientDataSetIngredientsdSer.Clear;
1315
      ClientDataSetIngredientsSerd.Value := 0;
1316
    end
1317
    else
1318
    begin
1319
      ClientDataSetIngredientsSer.Value := OutputAA(ClientDataSetInraAfzSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1320
      if ClientDataSetIngredientsSer.Value = 0
1321
      then
1322
        ClientDataSetIngredientsSer_MAT.Clear
1323
      else
1324
        ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1325
      if ClientDataSetInraAfzdSer.IsNull
1326
      then
1327
        ClientDataSetIngredientsdSer.Value := dSer * 100
1328
      else
1329
        ClientDataSetIngredientsdSer.Value := ClientDataSetInraAfzdSer.Value * 100;
1330
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value / 100 * ClientDataSetIngredientsSer.Value;
1331
    end;
1332
    // Pro
1333
    if ClientDataSetInraAfzPro.Value = 0
1334
    then
1335
    begin
1336
      ClientDataSetIngredientsPro.Value := 0;
1337
      ClientDataSetIngredientsPro_MAT.Clear;
1338
      ClientDataSetIngredientsdPro.Clear;
1339
      ClientDataSetIngredientsProd.Value := 0;
1340
    end
1341
    else
1342
    begin
1343
      ClientDataSetIngredientsPro.Value := OutputAA(ClientDataSetInraAfzPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1344
      if ClientDataSetIngredientsPro.Value = 0
1345
      then
1346
        ClientDataSetIngredientsPro_MAT.Clear
1347
      else
1348
        ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1349
      if ClientDataSetInraAfzdPro.IsNull
1350
      then
1351
        ClientDataSetIngredientsdPro.Value := dPro * 100
1352
      else
1353
        ClientDataSetIngredientsdPro.Value := ClientDataSetInraAfzdPro.Value * 100;
1354
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value / 100 * ClientDataSetIngredientsPro.Value;
1355
    end;
1356
  end;
1357
  // Min?raux
1358
  ClientDataSetIngredientsCa.Value := OutputMinerals(ClientDataSetInraAfzCa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1359
  ClientDataSetIngredientsP.Value := OutputMinerals(ClientDataSetInraAfzP.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1360
  ClientDataSetIngredientsNa.Value := OutputMinerals(ClientDataSetInraAfzNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1361
  ClientDataSetIngredientsK.Value := OutputMinerals(ClientDataSetInraAfzK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1362
  ClientDataSetIngredientsCl.Value := OutputMinerals(ClientDataSetInraAfzCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals);
1363
  ClientDataSetIngredientsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetIngredientsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
1364
  if ClientDataSetIngredientsP.Value = 0
1365
  then // En l'absence de P, il n'y a pas de dP
1366
  begin
1367
    ClientDataSetIngredientsdP.Clear;
1368
    ClientDataSetIngredientsdPphy.Clear;
1369
  end
1370
  else
1371
  begin
1372
    if ClientDataSetInraAfzdP.IsNull
1373
    then // Par d?faut dP = 20%
1374
      ClientDataSetIngredientsdP.Value := 20
1375
    else
1376
      ClientDataSetIngredientsdP.Value := ClientDataSetInraAfzdP.Value * 100;
1377
    if ClientDataSetInraAfzdPphy.IsNull
1378
    then // Par d?faut dPphy = dP
1379
      ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
1380
    else
1381
      ClientDataSetIngredientsdPphy.Value := ClientDataSetInraAfzdPphy.Value * 100;
1382
  end;
1383
  // Autres rapports
1384
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
1385
  then
1386
    ClientDataSetIngredientsLysd_ENc.Clear
1387
  else
1388
    if FormOptions.Energy = 0
1389
    then // g / MJ
1390
      if FormOptions.AA = 0
1391
      then // % (conversion)
1392
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
1393
      else // g/kg
1394
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
1395
    else // g / 1000 kcal
1396
      if FormOptions.AA = 0
1397
      then // % (conversion)
1398
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
1399
      else // g/kg
1400
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
1401
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
1402
  then
1403
    ClientDataSetIngredientsLysd_ENt.Clear
1404
  else
1405
    if FormOptions.Energy = 0
1406
    then // g / MJ
1407
      if FormOptions.AA = 0
1408
      then // % (conversion)
1409
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
1410
      else // g/kg
1411
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
1412
    else // g / 1000 kcal
1413
      if FormOptions.AA = 0
1414
      then // % (conversion)
1415
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
1416
      else // g/kg
1417
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
1418
end;
1419

    
1420
procedure TDataModuleDeclaration.CalcOriginal;
1421
// Renseigner l'enregistrement courant de ClientDataSetIngredients
1422
// ? partir de l'enregistrement courant de TableIngredients
1423
// en tenant compte des unit?s configur?es
1424
var
1425
  Nb: Integer;
1426
  Bonus, EB, dE, EDc, EDt, EM, EN, EqCB, EqADF, EqNDF, NUri, EUri, Res, ResD, ECH4, dMO, dN: Double;
1427
begin
1428
  // Analyse proximale -> valeurs saisies
1429
  RapMS := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MS']);
1430
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
1431
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
1432
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1433
  then
1434
    ClientDataSetIngredientsMM.Clear
1435
  else
1436
    ClientDataSetIngredientsMM.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1437
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1438
  then
1439
    ClientDataSetIngredientsMAT.Clear
1440
  else
1441
  begin
1442
    RapMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']);
1443
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
1444
  end;
1445
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1446
  then
1447
    ClientDataSetIngredientsMG.Clear
1448
  else
1449
    ClientDataSetIngredientsMG.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1450
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1451
  then
1452
    ClientDataSetIngredientsCB.Clear
1453
  else
1454
    ClientDataSetIngredientsCB.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1455
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1456
  then
1457
    ClientDataSetIngredientsNDF.Clear
1458
  else
1459
    ClientDataSetIngredientsNDF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1460
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1461
  then
1462
    ClientDataSetIngredientsADF.Clear
1463
  else
1464
    ClientDataSetIngredientsADF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1465
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
1466
  then
1467
    ClientDataSetIngredientsADL.Clear
1468
  else
1469
    ClientDataSetIngredientsADL.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADL']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1470
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1471
  then
1472
    ClientDataSetIngredientsAmidon.Clear
1473
  else
1474
    ClientDataSetIngredientsAmidon.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1475
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1476
  then
1477
    ClientDataSetIngredientsSucres.Clear
1478
  else
1479
    ClientDataSetIngredientsSucres.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']), RapMS, FormOptions.Expression, FormOptions.Proximal);
1480
  // Energie
1481
  EB := 0;
1482
  dE := 0;
1483
  EDc := 0;
1484
  EDt := 0;
1485
  EM := 0;
1486
//  EN := 0;
1487
  NUri := 0;
1488
//  EUri := 0;
1489
  Res := 0;
1490
//  ResD := 0;
1491
//  ECH4 := 0;
1492
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['EB'])
1493
  then // EB calcul?e
1494
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1495
    or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1496
    or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1497
    then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1498
      ClientDataSetIngredientsEB.Clear
1499
    else
1500
    begin
1501
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1502
      then
1503
        EqCB := 0
1504
      else
1505
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1506
        then // Equation SANS sucres
1507
          EqCB := 17.57 + 5.35 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.68 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.61 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.84 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB'])
1508
        else // Equation AVEC sucres
1509
          EqCB := 17.56 + 5.51 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.48 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 17.74 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.59 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - 1.14 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1510
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1511
      then
1512
        EqADF := 0
1513
      else
1514
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1515
        then // Equation SANS sucres
1516
          EqADF := 17.58 + 5.29 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.71 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.58 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.38 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF'])
1517
        else // Equation AVEC sucres
1518
          EqADF := 17.56 + 5.45 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.50 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 17.69 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 2.16 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - 1.15 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1519
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1520
      then
1521
        EqNDF := 0
1522
      else
1523
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1524
        then // Equation SANS sucres
1525
          EqNDF := 17.40 + 5.73 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.76 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.73 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 1.61 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF'])
1526
        else // Equation AVEC sucres
1527
          EqNDF := 17.41 + 5.79 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.63 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 18.12 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) + 1.48 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - 0.72 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1528
      Nb := 0;
1529
      if EqCB <> 0 then Inc(Nb);
1530
      if EqADF <> 0 then Inc(Nb);
1531
      if EqNDF <> 0 then Inc(Nb);
1532
      if Nb = 0
1533
      then // Equations sans valeur de fibre (ne devrait pas se produire)
1534
        if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1535
        then // Equation SANS amidon
1536
          if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1537
          then // Equation SANS sucres
1538
            EB := 17.64 + 4.78 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.80 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 15.88 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])
1539
          else // Equation AVEC sucres
1540
            EB := 17.61 + 5.05 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.53 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 15.06 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - 1.48 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres'])
1541
        else // Equation AVEC amidon
1542
          if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1543
          then // Equation SANS sucres
1544
            EB := 18.47 + 4.14 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 21.08 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 19.64 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - 0.92 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon'])
1545
          else // Equation AVEC sucres
1546
            EB := 18.88 + 4.24 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 20.25 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - 20.37 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - 1.42 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 2.38 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres'])
1547
      else // Moyenne des ?quations significatives
1548
        EB := (EqCB + EqADF + EqNDF) / Nb;
1549
      ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
1550
    end
1551
  else // EB fournie par l'utilisateur
1552
  begin
1553
    EB := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['EB']);
1554
    ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
1555
  end;
1556
  Bonus := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Bonus']) * 100;
1557
  ClientDataSetIngredientsBonus.Value := Bonus;
1558
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1559
  then
1560
    EqCB := 0
1561
  else
1562
    EqCB := 90.1 - 157.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1563
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1564
  then
1565
    EqNDF := 0
1566
  else
1567
    EqNDF := 98.3 - 90.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1568
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1569
  then
1570
    EqADF := 0
1571
  else
1572
    EqADF := 90.8 - 143.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1573
  Nb := 0;
1574
  if EqCB <> 0 then Inc(Nb);
1575
  if EqNDF <> 0 then Inc(Nb);
1576
  if EqADF <> 0 then Inc(Nb);
1577
  if Nb = 0
1578
  then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1579
    ClientDataSetIngredientsdEc.Clear
1580
  else // Moyenne des ?quations significatives
1581
  begin
1582
    dE := (EqCB + EqNDF + EqADF) / Nb + Bonus;
1583
    ClientDataSetIngredientsdEc.Value := dE;
1584
  end;
1585
  if ClientDataSetIngredientsEB.IsNull or ClientDataSetIngredientsdEc.IsNull
1586
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1587
    ClientDataSetIngredientsEDc.Clear
1588
  else
1589
  begin
1590
    EDc := EB * dE / 100;
1591
    ClientDataSetIngredientsEDc.Value := OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy);
1592
  end;
1593
  if ClientDataSetIngredientsEDc.IsNull
1594
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1595
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1596
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1597
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1598
  then // Informations insuffisantes pour calculer
1599
  begin
1600
    ClientDataSetIngredientsEMc.Clear;
1601
    ClientDataSetIngredientsEMc_EDc.Clear;
1602
  end
1603
  else
1604
  begin
1605
    NUri := 0.4 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) / 6.25;
1606
    EUri := CALORIE * (0.046 + 7.4 * NUri);
1607
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
1608
    then // par d?faut, on estime les sucres ? 2 % MS
1609
      Res := 1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 0.02
1610
    else
1611
      Res := 1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']);
1612
    ResD := 0.5 * Res;
1613
    ECH4 := CALORIE * 0.16 * ResD;
1614
    EM := EDc - EUri - ECH4;
1615
    ClientDataSetIngredientsEMc.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
1616
    if EDc = 0
1617
    then // Division par 0
1618
      ClientDataSetIngredientsEMc_EDc.Clear
1619
    else
1620
      ClientDataSetIngredientsEMc_EDc.Value := EM / EDc * 100;
1621
  end;
1622
  if ClientDataSetIngredientsEDc.IsNull
1623
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1624
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1625
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1626
  then // Informations insuffisantes pour calculer
1627
  begin
1628
    ClientDataSetIngredientsENc.Clear;
1629
    ClientDataSetIngredientsENc_EMc.Clear;
1630
  end
1631
  else
1632
  begin
1633
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1634
    then
1635
      EqCB := 0
1636
    else
1637
      EqCB := 0.703 * EDc - 4.04 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.62 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 4.09 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1638
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1639
    then
1640
      EqNDF := 0
1641
    else
1642
      EqNDF := 0.703 * EDc - 4.10 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.64 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 1.34 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1643
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1644
    then
1645
      EqADF := 0
1646
    else
1647
      EqADF := 0.700 * EDc - 3.82 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.74 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 2.02 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 3.65 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1648
    Nb := 0;
1649
    if EqCB <> 0 then Inc(Nb);
1650
    if EqNDF <> 0 then Inc(Nb);
1651
    if EqADF <> 0 then Inc(Nb);
1652
    if Nb = 0
1653
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1654
    begin
1655
      ClientDataSetIngredientsENc.Clear;
1656
      ClientDataSetIngredientsENc_EMc.Clear;
1657
    end
1658
    else // Moyenne des ?quations significatives
1659
    begin
1660
      EN := (EqCB + EqNDF + EqADF) / Nb;
1661
      ClientDataSetIngredientsENc.Value := OutputEnergy(EN, RapMS, FormOptions.Expression, FormOptions.Energy);
1662
      if EM = 0
1663
      then // Division par 0
1664
        ClientDataSetIngredientsENc_EMc.Clear
1665
      else
1666
        ClientDataSetIngredientsENc_EMc.Value := EN / EM * 100;
1667
    end;
1668
  end;
1669
  if ClientDataSetIngredientsEDc.IsNull
1670
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1671
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1672
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1673
  begin
1674
    ClientDataSetIngredientsEDt.Clear;
1675
    ClientDataSetIngredientsEDt_EDc.Clear;
1676
  end
1677
  else
1678
  begin
1679
    dMO := (7.45 + 0.949 * dE - 4.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT'])) / 100;
1680
    EDt := EDc + CALORIE * (1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])) * (1 - dMO);
1681
    ClientDataSetIngredientsEDt.Value := OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy);
1682
    if EDc = 0
1683
    then // Division par 0
1684
      ClientDataSetIngredientsEDt_EDc.Clear
1685
    else
1686
      ClientDataSetIngredientsEDt_EDc.Value := EDt / EDc * 100;
1687
  end;
1688
  if ClientDataSetIngredientsEDt.IsNull
1689
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
1690
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1691
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1692
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1693
  then // Informations insuffisantes pour calculer
1694
  begin
1695
    ClientDataSetIngredientsEMt.Clear;
1696
    ClientDataSetIngredientsEMt_EDt.Clear;
1697
  end
1698
  else
1699
  begin
1700
//    NUri := 0.4 * TableIngredients.FieldByName('MAT').AsFloat / 6.25;
1701
    EUri := CALORIE * (0.052 + 7.4 * NUri);
1702
//    if TableIngredients.FieldByName('Sucres').IsNull
1703
//    then // par d?faut, on estime les sucres ? 2 % MS
1704
//      Res := 1 - TableIngredients.FieldByName('MM').AsFloat - TableIngredients.FieldByName('MAT').AsFloat - TableIngredients.FieldByName('MG').AsFloat - TableIngredients.FieldByName('Amidon').AsFloat - 0.02
1705
//    else
1706
//      Res := 1 - TableIngredients.FieldByName('MM').AsFloat - TableIngredients.FieldByName('MAT').AsFloat - TableIngredients.FieldByName('MG').AsFloat - TableIngredients.FieldByName('Amidon').AsFloat - TableIngredients.FieldByName('Sucres').AsFloat;
1707
    ResD := 0.6 * Res;
1708
    ECH4 := CALORIE * 0.32 * ResD;
1709
    EM := EDt - EUri - ECH4;
1710
    ClientDataSetIngredientsEMt.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
1711
    if EDt = 0
1712
    then // Division par 0
1713
      ClientDataSetIngredientsEMt_EDt.Clear
1714
    else
1715
      ClientDataSetIngredientsEMt_EDt.Value := EM / EDt * 100;
1716
  end;
1717
  if ClientDataSetIngredientsEDt.IsNull
1718
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1719
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
1720
  or TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
1721
  then // Informations insuffisantes pour calculer
1722
  begin
1723
    ClientDataSetIngredientsENt.Clear;
1724
    ClientDataSetIngredientsENt_EMt.Clear;
1725
  end
1726
  else
1727
  begin
1728
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1729
    then
1730
      EqCB := 0
1731
    else
1732
      EqCB := 0.703 * EDt - 4.04 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.62 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 4.09 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1733
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1734
    then
1735
      EqNDF := 0
1736
    else
1737
      EqNDF := 0.703 * EDt - 4.10 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.64 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 1.97 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 1.34 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1738
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1739
    then
1740
      EqADF := 0
1741
    else
1742
      EqADF := 0.700 * EDt - 3.82 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) + 6.74 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) + 2.02 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - 3.65 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1743
    Nb := 0;
1744
    if EqCB <> 0 then Inc(Nb);
1745
    if EqNDF <> 0 then Inc(Nb);
1746
    if EqADF <> 0 then Inc(Nb);
1747
    if Nb = 0
1748
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1749
    begin
1750
      ClientDataSetIngredientsENt.Clear;
1751
      ClientDataSetIngredientsENt_EMt.Clear;
1752
    end
1753
    else // Moyenne des ?quations significatives
1754
    begin
1755
      EN := (EqCB + EqNDF + EqADF) / Nb;
1756
      ClientDataSetIngredientsENt.Value := OutputEnergy(EN, RapMS, FormOptions.Expression, FormOptions.Energy);
1757
      if EM = 0
1758
      then // Division par 0
1759
        ClientDataSetIngredientsENt_EMt.Clear
1760
      else
1761
        ClientDataSetIngredientsENt_EMt.Value := EN / EM * 100;
1762
    end;
1763
  end;
1764
  if ClientDataSetIngredientsEDt.IsNull or ClientDataSetIngredientsEB.IsNull or (ClientDataSetIngredientsEB.Value = 0)
1765
  then
1766
    ClientDataSetIngredientsdEt.Clear
1767
  else
1768
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
1769
  if ClientDataSetIngredientsEMt.IsNull or ClientDataSetIngredientsEMc.IsNull or (ClientDataSetIngredientsEMc.Value = 0)
1770
  then
1771
    ClientDataSetIngredientsEMt_EMc.Clear
1772
  else
1773
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
1774
  if ClientDataSetIngredientsENt.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
1775
  then
1776
    ClientDataSetIngredientsENt_ENc.Clear
1777
  else
1778
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
1779
  // Digestibilit? f?cale de l'azote
1780
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
1781
  then // Informations insuffisantes pour calculer (ne devrait pas se produire)
1782
  begin
1783
    ClientDataSetIngredientsdNc.Clear;
1784
    ClientDataSetIngredientsdNt.Clear;
1785
  end
1786
  else
1787
  begin
1788
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1789
    then
1790
      EqCB := 0
1791
    else
1792
      EqCB := 76.8 + 69.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 122.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1793
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1794
    then
1795
      EqNDF := 0
1796
    else
1797
      EqNDF := 81.3 + 79.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 69.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1798
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1799
    then
1800
      EqADF := 0
1801
    else
1802
      EqADF := 77.4 + 70.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 116.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1803
    Nb := 0;
1804
    if EqCB <> 0 then Inc(Nb);
1805
    if EqNDF <> 0 then Inc(Nb);
1806
    if EqADF <> 0 then Inc(Nb);
1807
    if Nb = 0
1808
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1809
      ClientDataSetIngredientsdNc.Clear
1810
    else // Moyenne des ?quations significatives
1811
    begin
1812
      dN := (EqCB + EqNDF + EqADF) / Nb;
1813
      ClientDataSetIngredientsdNc.Value := dN;
1814
    end;
1815
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
1816
    then
1817
      EqCB := 0
1818
    else
1819
      EqCB := 77.9 + 77.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 87.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']);
1820
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
1821
   then
1822
      EqNDF := 0
1823
    else
1824
      EqNDF := 79.9 + 86.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 44.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']);
1825
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
1826
    then
1827
      EqADF := 0
1828
    else
1829
      EqADF := 78.3 + 78.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - 83.0 * TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']);
1830
    Nb := 0;
1831
    if EqCB <> 0 then Inc(Nb);
1832
    if EqNDF <> 0 then Inc(Nb);
1833
    if EqADF <> 0 then Inc(Nb);
1834
    if Nb = 0
1835
    then // Faute de valeur de fibres, on ne peut calculer la digestibilit? (ne devrait pas se produire)
1836
      ClientDataSetIngredientsdNt.Clear
1837
    else // Moyenne des ?quations significatives
1838
    begin
1839
      dN := (EqCB + EqNDF + EqADF) / Nb;
1840
      ClientDataSetIngredientsdNt.Value := dN;
1841
    end;
1842
  end;
1843
  // Acides amin?s
1844
  if RapMAT = 0
1845
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
1846
  begin
1847
    // Teneurs
1848
    ClientDataSetIngredientsLys.Value := 0;
1849
    ClientDataSetIngredientsThr.Value := 0;
1850
    ClientDataSetIngredientsMet.Value := 0;
1851
    ClientDataSetIngredientsCys.Value := 0;
1852
    ClientDataSetIngredientsMetCys.Value := 0;
1853
    ClientDataSetIngredientsTrp.Value := 0;
1854
    ClientDataSetIngredientsIle.Value := 0;
1855
    ClientDataSetIngredientsVal.Value := 0;
1856
    ClientDataSetIngredientsLeu.Value := 0;
1857
    ClientDataSetIngredientsPhe.Value := 0;
1858
    ClientDataSetIngredientsTyr.Value := 0;
1859
    ClientDataSetIngredientsPheTyr.Value := 0;
1860
    ClientDataSetIngredientsHis.Value := 0;
1861
    ClientDataSetIngredientsArg.Value := 0;
1862
    ClientDataSetIngredientsAla.Value := 0;
1863
    ClientDataSetIngredientsAsp.Value := 0;
1864
    ClientDataSetIngredientsGlu.Value := 0;
1865
    ClientDataSetIngredientsGly.Value := 0;
1866
    ClientDataSetIngredientsSer.Value := 0;
1867
    ClientDataSetIngredientsPro.Value := 0;
1868
    // % MAT
1869
    ClientDataSetIngredientsLys_MAT.Clear;
1870
    ClientDataSetIngredientsThr_MAT.Clear;
1871
    ClientDataSetIngredientsMet_MAT.Clear;
1872
    ClientDataSetIngredientsCys_MAT.Clear;
1873
    ClientDataSetIngredientsMetCys_MAT.Clear;
1874
    ClientDataSetIngredientsTrp_MAT.Clear;
1875
    ClientDataSetIngredientsIle_MAT.Clear;
1876
    ClientDataSetIngredientsVal_MAT.Clear;
1877
    ClientDataSetIngredientsLeu_MAT.Clear;
1878
    ClientDataSetIngredientsPhe_MAT.Clear;
1879
    ClientDataSetIngredientsTyr_MAT.Clear;
1880
    ClientDataSetIngredientsPheTyr_MAT.Clear;
1881
    ClientDataSetIngredientsHis_MAT.Clear;
1882
    ClientDataSetIngredientsArg_MAT.Clear;
1883
    ClientDataSetIngredientsAla_MAT.Clear;
1884
    ClientDataSetIngredientsAsp_MAT.Clear;
1885
    ClientDataSetIngredientsGlu_MAT.Clear;
1886
    ClientDataSetIngredientsGly_MAT.Clear;
1887
    ClientDataSetIngredientsSer_MAT.Clear;
1888
    ClientDataSetIngredientsPro_MAT.Clear;
1889
    // Digestibilit?s
1890
    ClientDataSetIngredientsdLys.Clear;
1891
    ClientDataSetIngredientsdThr.Clear;
1892
    ClientDataSetIngredientsdMet.Clear;
1893
    ClientDataSetIngredientsdCys.Clear;
1894
    ClientDataSetIngredientsdMetCys.Clear;
1895
    ClientDataSetIngredientsdTrp.Clear;
1896
    ClientDataSetIngredientsdIle.Clear;
1897
    ClientDataSetIngredientsdVal.Clear;
1898
    ClientDataSetIngredientsdLeu.Clear;
1899
    ClientDataSetIngredientsdPhe.Clear;
1900
    ClientDataSetIngredientsdTyr.Clear;
1901
    ClientDataSetIngredientsdPheTyr.Clear;
1902
    ClientDataSetIngredientsdHis.Clear;
1903
    ClientDataSetIngredientsdArg.Clear;
1904
    ClientDataSetIngredientsdAla.Clear;
1905
    ClientDataSetIngredientsdAsp.Clear;
1906
    ClientDataSetIngredientsdGlu.Clear;
1907
    ClientDataSetIngredientsdGly.Clear;
1908
    ClientDataSetIngredientsdSer.Clear;
1909
    ClientDataSetIngredientsdPro.Clear;
1910
    // Teneurs digestibles
1911
    ClientDataSetIngredientsLysd.Value := 0;
1912
    ClientDataSetIngredientsThrd.Value := 0;
1913
    ClientDataSetIngredientsMetd.Value := 0;
1914
    ClientDataSetIngredientsCysd.Value := 0;
1915
    ClientDataSetIngredientsMetCysd.Value := 0;
1916
    ClientDataSetIngredientsTrpd.Value := 0;
1917
    ClientDataSetIngredientsIled.Value := 0;
1918
    ClientDataSetIngredientsVald.Value := 0;
1919
    ClientDataSetIngredientsLeud.Value := 0;
1920
    ClientDataSetIngredientsPhed.Value := 0;
1921
    ClientDataSetIngredientsTyrd.Value := 0;
1922
    ClientDataSetIngredientsPheTyrd.Value := 0;
1923
    ClientDataSetIngredientsHisd.Value := 0;
1924
    ClientDataSetIngredientsArgd.Value := 0;
1925
    ClientDataSetIngredientsAlad.Value := 0;
1926
    ClientDataSetIngredientsAspd.Value := 0;
1927
    ClientDataSetIngredientsGlud.Value := 0;
1928
    ClientDataSetIngredientsGlyd.Value := 0;
1929
    ClientDataSetIngredientsSerd.Value := 0;
1930
    ClientDataSetIngredientsProd.Value := 0;
1931
  end
1932
  else
1933
  begin
1934
    // Lys
1935
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
1936
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']) = 0)
1937
    then
1938
    begin
1939
      ClientDataSetIngredientsLys.Value := 0;
1940
      ClientDataSetIngredientsLys_MAT.Clear;
1941
      ClientDataSetIngredientsdLys.Clear;
1942
      ClientDataSetIngredientsLysd.Value := 0;
1943
    end
1944
    else
1945
    begin
1946
      ClientDataSetIngredientsLys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1947
      if ClientDataSetIngredientsLys.Value = 0
1948
      then
1949
        ClientDataSetIngredientsLys_MAT.Clear
1950
      else
1951
        ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1952
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dLys'])
1953
      then
1954
        ClientDataSetIngredientsdLys.Value := dLys * 100
1955
      else
1956
        ClientDataSetIngredientsdLys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dLys']) * 100;
1957
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value * ClientDataSetIngredientsLys.Value / 100;
1958
    end;
1959
    // Thr
1960
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
1961
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']) = 0)
1962
    then
1963
    begin
1964
      ClientDataSetIngredientsThr.Value := 0;
1965
      ClientDataSetIngredientsThr_MAT.Clear;
1966
      ClientDataSetIngredientsdThr.Clear;
1967
      ClientDataSetIngredientsThrd.Value := 0;
1968
    end
1969
    else
1970
    begin
1971
      ClientDataSetIngredientsThr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1972
      if ClientDataSetIngredientsThr.Value = 0
1973
      then
1974
        ClientDataSetIngredientsThr_MAT.Clear
1975
      else
1976
        ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
1977
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dThr'])
1978
      then
1979
        ClientDataSetIngredientsdThr.Value := dThr * 100
1980
      else
1981
        ClientDataSetIngredientsdThr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dThr']) * 100;
1982
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value * ClientDataSetIngredientsThr.Value / 100;
1983
    end;
1984
    // Met
1985
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
1986
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']) = 0)
1987
    then
1988
    begin
1989
      ClientDataSetIngredientsMet.Value := 0;
1990
      ClientDataSetIngredientsMet_MAT.Clear;
1991
      ClientDataSetIngredientsdMet.Clear;
1992
      ClientDataSetIngredientsMetd.Value := 0;
1993
    end
1994
    else
1995
    begin
1996
      ClientDataSetIngredientsMet.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
1997
      if ClientDataSetIngredientsMet.Value = 0
1998
      then
1999
        ClientDataSetIngredientsMet_MAT.Clear
2000
      else
2001
        ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2002
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dMet'])
2003
      then
2004
        ClientDataSetIngredientsdMet.Value := dMet * 100
2005
      else
2006
        ClientDataSetIngredientsdMet.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dMet']) * 100;
2007
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value * ClientDataSetIngredientsMet.Value / 100;
2008
    end;
2009
    // Cys
2010
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
2011
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']) = 0)
2012
    then
2013
    begin
2014
      ClientDataSetIngredientsCys.Value := 0;
2015
      ClientDataSetIngredientsCys_MAT.Clear;
2016
      ClientDataSetIngredientsdCys.Clear;
2017
      ClientDataSetIngredientsCysd.Value := 0;
2018
    end
2019
    else
2020
    begin
2021
      ClientDataSetIngredientsCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2022
      if ClientDataSetIngredientsCys.Value = 0
2023
      then
2024
        ClientDataSetIngredientsCys_MAT.Clear
2025
      else
2026
        ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2027
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dCys'])
2028
      then
2029
        ClientDataSetIngredientsdCys.Value := dCys * 100
2030
      else
2031
        ClientDataSetIngredientsdCys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dCys']) * 100;
2032
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value * ClientDataSetIngredientsCys.Value / 100;
2033
    end;
2034
    // Met + Cys
2035
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
2036
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']) = 0)
2037
    then
2038
    begin
2039
      ClientDataSetIngredientsMetCys.Value := 0;
2040
      ClientDataSetIngredientsMetCys_MAT.Clear;
2041
      ClientDataSetIngredientsdMetCys.Clear;
2042
      ClientDataSetIngredientsMetCysd.Value := 0;
2043
    end
2044
    else
2045
    begin
2046
      ClientDataSetIngredientsMetCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2047
      if ClientDataSetIngredientsMetCys.Value = 0
2048
      then
2049
        ClientDataSetIngredientsMetCys_MAT.Clear
2050
      else
2051
        ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2052
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dMetCys'])
2053
      then
2054
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
2055
      else
2056
        ClientDataSetIngredientsdMetCys.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dMetCys']) * 100;
2057
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value * ClientDataSetIngredientsMetCys.Value / 100;
2058
    end;
2059
    // Trp
2060
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
2061
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']) = 0)
2062
    then
2063
    begin
2064
      ClientDataSetIngredientsTrp.Value := 0;
2065
      ClientDataSetIngredientsTrp_MAT.Clear;
2066
      ClientDataSetIngredientsdTrp.Clear;
2067
      ClientDataSetIngredientsTrpd.Value := 0;
2068
    end
2069
    else
2070
    begin
2071
      ClientDataSetIngredientsTrp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2072
      if ClientDataSetIngredientsTrp.Value = 0
2073
      then
2074
        ClientDataSetIngredientsTrp_MAT.Clear
2075
      else
2076
        ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2077
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dTrp'])
2078
      then
2079
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
2080
      else
2081
        ClientDataSetIngredientsdTrp.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dTrp']) * 100;
2082
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value * ClientDataSetIngredientsTrp.Value / 100;
2083
    end;
2084
    // Ile
2085
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
2086
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']) = 0)
2087
    then
2088
    begin
2089
      ClientDataSetIngredientsIle.Value := 0;
2090
      ClientDataSetIngredientsIle_MAT.Clear;
2091
      ClientDataSetIngredientsdIle.Clear;
2092
      ClientDataSetIngredientsIled.Value := 0;
2093
    end
2094
    else
2095
    begin
2096
      ClientDataSetIngredientsIle.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2097
      if ClientDataSetIngredientsIle.Value = 0
2098
      then
2099
        ClientDataSetIngredientsIle_MAT.Clear
2100
      else
2101
        ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2102
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dIle'])
2103
      then
2104
        ClientDataSetIngredientsdIle.Value := dIle * 100
2105
      else
2106
        ClientDataSetIngredientsdIle.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dIle']) * 100;
2107
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value * ClientDataSetIngredientsIle.Value / 100;
2108
    end;
2109
    // Val
2110
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
2111
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']) = 0)
2112
    then
2113
    begin
2114
      ClientDataSetIngredientsVal.Value := 0;
2115
      ClientDataSetIngredientsVal_MAT.Clear;
2116
      ClientDataSetIngredientsdVal.Clear;
2117
      ClientDataSetIngredientsVald.Value := 0;
2118
    end
2119
    else
2120
    begin
2121
      ClientDataSetIngredientsVal.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2122
      if ClientDataSetIngredientsVal.Value = 0
2123
      then
2124
        ClientDataSetIngredientsVal_MAT.Clear
2125
      else
2126
        ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2127
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dVal'])
2128
      then
2129
        ClientDataSetIngredientsdVal.Value := dVal * 100
2130
      else
2131
        ClientDataSetIngredientsdVal.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dVal']) * 100;
2132
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value * ClientDataSetIngredientsVal.Value / 100;
2133
    end;
2134
    // Leu
2135
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
2136
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']) = 0)
2137
    then
2138
    begin
2139
      ClientDataSetIngredientsLeu.Value := 0;
2140
      ClientDataSetIngredientsLeu_MAT.Clear;
2141
      ClientDataSetIngredientsdLeu.Clear;
2142
      ClientDataSetIngredientsLeud.Value := 0;
2143
    end
2144
    else
2145
    begin
2146
      ClientDataSetIngredientsLeu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2147
      if ClientDataSetIngredientsLeu.Value = 0
2148
      then
2149
        ClientDataSetIngredientsLeu_MAT.Clear
2150
      else
2151
        ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2152
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dLeu'])
2153
      then
2154
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
2155
      else
2156
        ClientDataSetIngredientsdLeu.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dLeu']) * 100;
2157
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value * ClientDataSetIngredientsLeu.Value / 100;
2158
    end;
2159
    // Phe
2160
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
2161
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']) = 0)
2162
    then
2163
    begin
2164
      ClientDataSetIngredientsPhe.Value := 0;
2165
      ClientDataSetIngredientsPhe_MAT.Clear;
2166
      ClientDataSetIngredientsdPhe.Clear;
2167
      ClientDataSetIngredientsPhed.Value := 0;
2168
    end
2169
    else
2170
    begin
2171
      ClientDataSetIngredientsPhe.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2172
      if ClientDataSetIngredientsPhe.Value = 0
2173
      then
2174
        ClientDataSetIngredientsPhe_MAT.Clear
2175
      else
2176
        ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2177
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPhe'])
2178
      then
2179
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
2180
      else
2181
        ClientDataSetIngredientsdPhe.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPhe']) * 100;
2182
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value * ClientDataSetIngredientsPhe.Value / 100;
2183
    end;
2184
    // Tyr
2185
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
2186
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']) = 0)
2187
    then
2188
    begin
2189
      ClientDataSetIngredientsTyr.Value := 0;
2190
      ClientDataSetIngredientsTyr_MAT.Clear;
2191
      ClientDataSetIngredientsdTyr.Clear;
2192
      ClientDataSetIngredientsTyrd.Value := 0;
2193
    end
2194
    else
2195
    begin
2196
      ClientDataSetIngredientsTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2197
      if ClientDataSetIngredientsTyr.Value = 0
2198
      then
2199
        ClientDataSetIngredientsTyr_MAT.Clear
2200
      else
2201
        ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2202
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dTyr'])
2203
      then
2204
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
2205
      else
2206
        ClientDataSetIngredientsdTyr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dTyr']) * 100;
2207
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value * ClientDataSetIngredientsTyr.Value / 100;
2208
    end;
2209
    // Phe + Tyr
2210
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
2211
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']) = 0)
2212
    then
2213
    begin
2214
      ClientDataSetIngredientsPheTyr.Value := 0;
2215
      ClientDataSetIngredientsPheTyr_MAT.Clear;
2216
      ClientDataSetIngredientsdPheTyr.Clear;
2217
      ClientDataSetIngredientsPheTyrd.Value := 0;
2218
    end
2219
    else
2220
    begin
2221
      ClientDataSetIngredientsPheTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2222
      if ClientDataSetIngredientsPheTyr.Value = 0
2223
      then
2224
        ClientDataSetIngredientsPheTyr_MAT.Clear
2225
      else
2226
        ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2227
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPheTyr'])
2228
      then
2229
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
2230
      else
2231
        ClientDataSetIngredientsdPheTyr.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPheTyr']) * 100;
2232
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value * ClientDataSetIngredientsPheTyr.Value / 100;
2233
    end;
2234
    // His
2235
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
2236
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']) = 0)
2237
    then
2238
    begin
2239
      ClientDataSetIngredientsHis.Value := 0;
2240
      ClientDataSetIngredientsHis_MAT.Clear;
2241
      ClientDataSetIngredientsdHis.Clear;
2242
      ClientDataSetIngredientsHisd.Value := 0;
2243
    end
2244
    else
2245
    begin
2246
      ClientDataSetIngredientsHis.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2247
      if ClientDataSetIngredientsHis.Value = 0
2248
      then
2249
        ClientDataSetIngredientsHis_MAT.Clear
2250
      else
2251
        ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2252
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dHis'])
2253
      then
2254
        ClientDataSetIngredientsdHis.Value := dHis * 100
2255
      else
2256
        ClientDataSetIngredientsdHis.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dHis']) * 100;
2257
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value * ClientDataSetIngredientsHis.Value / 100;
2258
    end;
2259
    // Arg
2260
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
2261
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']) = 0)
2262
    then
2263
    begin
2264
      ClientDataSetIngredientsArg.Value := 0;
2265
      ClientDataSetIngredientsArg_MAT.Clear;
2266
      ClientDataSetIngredientsdArg.Clear;
2267
      ClientDataSetIngredientsArgd.Value := 0;
2268
    end
2269
    else
2270
    begin
2271
      ClientDataSetIngredientsArg.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2272
      if ClientDataSetIngredientsArg.Value = 0
2273
      then
2274
        ClientDataSetIngredientsArg_MAT.Clear
2275
      else
2276
        ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2277
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dArg'])
2278
      then
2279
        ClientDataSetIngredientsdArg.Value := dArg * 100
2280
      else
2281
        ClientDataSetIngredientsdArg.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dArg']) * 100;
2282
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value * ClientDataSetIngredientsArg.Value / 100;
2283
    end;
2284
    // Ala
2285
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
2286
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']) = 0)
2287
    then
2288
    begin
2289
      ClientDataSetIngredientsAla.Value := 0;
2290
      ClientDataSetIngredientsAla_MAT.Clear;
2291
      ClientDataSetIngredientsdAla.Clear;
2292
      ClientDataSetIngredientsAlad.Value := 0;
2293
    end
2294
    else
2295
    begin
2296
      ClientDataSetIngredientsAla.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2297
      if ClientDataSetIngredientsAla.Value = 0
2298
      then
2299
        ClientDataSetIngredientsAla_MAT.Clear
2300
      else
2301
        ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2302
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dAla'])
2303
      then
2304
        ClientDataSetIngredientsdAla.Value := dAla * 100
2305
      else
2306
        ClientDataSetIngredientsdAla.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dAla']) * 100;
2307
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value * ClientDataSetIngredientsAla.Value / 100;
2308
    end;
2309
    // Asp
2310
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
2311
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']) = 0)
2312
    then
2313
    begin
2314
      ClientDataSetIngredientsAsp.Value := 0;
2315
      ClientDataSetIngredientsAsp_MAT.Clear;
2316
      ClientDataSetIngredientsdAsp.Clear;
2317
      ClientDataSetIngredientsAspd.Value := 0;
2318
    end
2319
    else
2320
    begin
2321
      ClientDataSetIngredientsAsp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2322
      if ClientDataSetIngredientsAsp.Value = 0
2323
      then
2324
        ClientDataSetIngredientsAsp_MAT.Clear
2325
      else
2326
        ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2327
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dAsp'])
2328
      then
2329
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
2330
      else
2331
        ClientDataSetIngredientsdAsp.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dAsp']) * 100;
2332
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value * ClientDataSetIngredientsAsp.Value / 100;
2333
    end;
2334
    // Glu
2335
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
2336
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']) = 0)
2337
    then
2338
    begin
2339
      ClientDataSetIngredientsGlu.Value := 0;
2340
      ClientDataSetIngredientsGlu_MAT.Clear;
2341
      ClientDataSetIngredientsdGlu.Clear;
2342
      ClientDataSetIngredientsGlud.Value := 0;
2343
    end
2344
    else
2345
    begin
2346
      ClientDataSetIngredientsGlu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2347
      if ClientDataSetIngredientsGlu.Value = 0
2348
      then
2349
        ClientDataSetIngredientsGlu_MAT.Clear
2350
      else
2351
        ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2352
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dGlu'])
2353
      then
2354
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
2355
      else
2356
        ClientDataSetIngredientsdGlu.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dGlu']) * 100;
2357
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value * ClientDataSetIngredientsGlu.Value / 100;
2358
    end;
2359
    // Gly
2360
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
2361
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']) = 0)
2362
    then
2363
    begin
2364
      ClientDataSetIngredientsGly.Value := 0;
2365
      ClientDataSetIngredientsGly_MAT.Clear;
2366
      ClientDataSetIngredientsdGly.Clear;
2367
      ClientDataSetIngredientsGlyd.Value := 0;
2368
    end
2369
    else
2370
    begin
2371
      ClientDataSetIngredientsGly.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2372
      if ClientDataSetIngredientsGly.Value = 0
2373
      then
2374
        ClientDataSetIngredientsGly_MAT.Clear
2375
      else
2376
        ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2377
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dGly'])
2378
      then
2379
        ClientDataSetIngredientsdGly.Value := dGly * 100
2380
      else
2381
        ClientDataSetIngredientsdGly.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dGly']) * 100;
2382
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value * ClientDataSetIngredientsGly.Value / 100;
2383
    end;
2384
    // Ser
2385
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
2386
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']) = 0)
2387
    then
2388
    begin
2389
      ClientDataSetIngredientsSer.Value := 0;
2390
      ClientDataSetIngredientsSer_MAT.Clear;
2391
      ClientDataSetIngredientsdSer.Clear;
2392
      ClientDataSetIngredientsSerd.Value := 0;
2393
    end
2394
    else
2395
    begin
2396
      ClientDataSetIngredientsSer.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2397
      if ClientDataSetIngredientsSer.Value = 0
2398
      then
2399
        ClientDataSetIngredientsSer_MAT.Clear
2400
      else
2401
        ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2402
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dSer'])
2403
      then
2404
        ClientDataSetIngredientsdSer.Value := dSer * 100
2405
      else
2406
        ClientDataSetIngredientsdSer.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dSer']) * 100;
2407
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value * ClientDataSetIngredientsSer.Value / 100;
2408
    end;
2409
    // Pro
2410
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
2411
    or (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']) = 0)
2412
    then
2413
    begin
2414
      ClientDataSetIngredientsPro.Value := 0;
2415
      ClientDataSetIngredientsPro_MAT.Clear;
2416
      ClientDataSetIngredientsdPro.Clear;
2417
      ClientDataSetIngredientsProd.Value := 0;
2418
    end
2419
    else
2420
    begin
2421
      ClientDataSetIngredientsPro.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2422
      if ClientDataSetIngredientsPro.Value = 0
2423
      then
2424
        ClientDataSetIngredientsPro_MAT.Clear
2425
      else
2426
        ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2427
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPro'])
2428
      then
2429
        ClientDataSetIngredientsdPro.Value := dPro * 100
2430
      else
2431
        ClientDataSetIngredientsdPro.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPro']) * 100;
2432
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value * ClientDataSetIngredientsPro.Value / 100;
2433
    end;
2434
  end;
2435
  // Min?raux
2436
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
2437
  then
2438
    ClientDataSetIngredientsCa.Clear
2439
  else
2440
    ClientDataSetIngredientsCa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ca']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2441
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
2442
  then
2443
    ClientDataSetIngredientsP.Clear
2444
  else
2445
    ClientDataSetIngredientsP.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['P']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2446
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
2447
  then
2448
    ClientDataSetIngredientsNa.Clear
2449
  else
2450
    ClientDataSetIngredientsNa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Na']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2451
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
2452
  then
2453
    ClientDataSetIngredientsK.Clear
2454
  else
2455
    ClientDataSetIngredientsK.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['K']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2456
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
2457
  then
2458
    ClientDataSetIngredientsCl.Clear
2459
  else
2460
    ClientDataSetIngredientsCl.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cl']), RapMS, FormOptions.Expression, FormOptions.Minerals);
2461
  if ClientDataSetIngredientsNa.IsNull or ClientDataSetIngredientsK.IsNull or ClientDataSetIngredientsCl.IsNull
2462
  then
2463
    ClientDataSetIngredientsBE.Clear
2464
  else
2465
    ClientDataSetIngredientsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetIngredientsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
2466
  if ClientDataSetIngredientsP.Value = 0
2467
  then // En l'absence de P, il n'y a pas de dP
2468
  begin
2469
    ClientDataSetIngredientsdP.Clear;
2470
    ClientDataSetIngredientsdPphy.Clear;
2471
  end
2472
  else
2473
  begin
2474
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
2475
    then // Par d?faut dP = 20%
2476
      ClientDataSetIngredientsdP.Value := 20
2477
    else
2478
      ClientDataSetIngredientsdP.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dP']) * 100;
2479
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
2480
    then // Par d?faut dPphy = dP
2481
      ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
2482
    else
2483
      ClientDataSetIngredientsdPphy.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPphy']) * 100;
2484
  end;
2485
  // Autres rapports
2486
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
2487
  then
2488
    ClientDataSetIngredientsLysd_ENc.Clear
2489
  else
2490
    if FormOptions.Energy = 0
2491
    then // g / MJ
2492
      if FormOptions.AA = 0
2493
      then // % (conversion)
2494
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
2495
      else // g/kg
2496
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
2497
    else // g / 1000 kcal
2498
      if FormOptions.AA = 0
2499
      then // % (conversion)
2500
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
2501
      else // g/kg
2502
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
2503
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
2504
  then
2505
    ClientDataSetIngredientsLysd_ENt.Clear
2506
  else
2507
    if FormOptions.Energy = 0
2508
    then // g / MJ
2509
      if FormOptions.AA = 0
2510
      then // % (conversion)
2511
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
2512
      else // g/kg
2513
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
2514
    else // g / 1000 kcal
2515
      if FormOptions.AA = 0
2516
      then // % (conversion)
2517
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
2518
      else // g/kg
2519
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
2520
end;
2521

    
2522
procedure TDataModuleDeclaration.CalcCopy;
2523
// Renseigner l'enregistrement courant de ClientDataSetIngredients
2524
// ? partir de l'enregistrement courant de TableIngredients
2525
// en tenant compte des unit?s configur?es
2526
var
2527
  Nb: Integer;
2528
  Bonus, EB, dE, EDc, EDt, EM, EM_ED, EN_EM, dN: Double;
2529
  CorrMAT, CorrMG, CorrMM, CorrCB, CorrNDF, CorrADF, DiffMAT, DiffMG, DiffAmidon: Double;
2530
begin
2531
  // Analyse proximale
2532
  RapMS := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MS']);
2533
  ClientDataSetIngredientsMS.Value := OutputProximal(RapMS, 1, 1, FormOptions.Proximal);
2534
  ClientDataSetIngredientsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
2535
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2536
  then
2537
    ClientDataSetIngredientsMM.Value := OutputProximal(ClientDataSetInraAfzMM.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2538
  else
2539
    ClientDataSetIngredientsMM.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2540
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2541
  then
2542
  begin
2543
    RapMAT := ClientDataSetInraAfzMAT.Value;
2544
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
2545
  end
2546
  else
2547
  begin
2548
    RapMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']);
2549
    ClientDataSetIngredientsMAT.Value := OutputProximal(RapMAT, RapMS, FormOptions.Expression, FormOptions.Proximal);
2550
  end;
2551
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2552
  then
2553
    ClientDataSetIngredientsMG.Value := OutputProximal(ClientDataSetInraAfzMG.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2554
  else
2555
    ClientDataSetIngredientsMG.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2556
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2557
  then
2558
    ClientDataSetIngredientsCB.Value := OutputProximal(ClientDataSetInraAfzCB.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2559
  else
2560
    ClientDataSetIngredientsCB.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2561
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2562
  then
2563
    ClientDataSetIngredientsNDF.Value := OutputProximal(ClientDataSetInraAfzNDF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2564
  else
2565
    ClientDataSetIngredientsNDF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2566
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2567
  then
2568
    ClientDataSetIngredientsADF.Value := OutputProximal(ClientDataSetInraAfzADF.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2569
  else
2570
    ClientDataSetIngredientsADF.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2571
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADL'])
2572
  then
2573
    ClientDataSetIngredientsADL.Value := OutputProximal(ClientDataSetInraAfzADL.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2574
  else
2575
    ClientDataSetIngredientsADL.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADL']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2576
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2577
  then
2578
    ClientDataSetIngredientsAmidon.Value := OutputProximal(ClientDataSetInraAfzAmidon.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2579
  else
2580
    ClientDataSetIngredientsAmidon.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2581
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Sucres'])
2582
  then
2583
    ClientDataSetIngredientsSucres.Value := OutputProximal(ClientDataSetInraAfzSucres.Value, RapMS, FormOptions.Expression, FormOptions.Proximal)
2584
  else
2585
    ClientDataSetIngredientsSucres.Value := OutputProximal(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Sucres']), RapMS, FormOptions.Expression, FormOptions.Proximal);
2586
  // Energie -> Valeurs calcul?es
2587
  EB := ClientDataSetInraAfzEB.Value;
2588
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2589
  then
2590
    CorrMAT := 0
2591
  else
2592
    CorrMAT := CoefMAT * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value);
2593
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2594
  then
2595
    CorrMG := 0
2596
  else
2597
    CorrMG := CoefMG * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value);
2598
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2599
  then
2600
    CorrMM := 0
2601
  else
2602
    CorrMM := CoefMM * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM']) - ClientDataSetInraAfzMM.Value);
2603
  // Correction : somme des corrections (born?e ? 0)
2604
  EB := Max(0, EB + CorrMAT + CorrMG + CorrMM);
2605
  ClientDataSetIngredientsEB.Value := OutputEnergy(EB, RapMS, FormOptions.Expression, FormOptions.Energy);
2606
  Bonus := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Bonus']) * 100;
2607
  ClientDataSetIngredientsBonus.Value := Bonus;
2608
  dE := ClientDataSetInraAfzdEc.Value * 100 + Bonus;
2609
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2610
  then
2611
    CorrCB := 0
2612
  else
2613
    CorrCB := ClientDataSetInraAfzCoefCB.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value) * 100;
2614
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2615
  then
2616
    CorrNDF := 0
2617
  else
2618
    CorrNDF := ClientDataSetInraAfzCoefNDF.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value) * 100;
2619
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2620
  then
2621
    CorrADF := 0
2622
  else
2623
    CorrADF := ClientDataSetInraAfzCoefADF.Value * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value) * 100;
2624
  Nb := 0;
2625
  if CorrCB <> 0 then Inc(Nb);
2626
  if CorrNDF <> 0 then Inc(Nb);
2627
  if CorrADF <> 0 then Inc(Nb);
2628
  if Nb > 0
2629
  then // Correction : moyenne des ?quations significatives (born?e ? 0)
2630
    dE := Max(0, dE + (CorrCB + CorrNDF + CorrADF) / Nb);
2631
  ClientDataSetIngredientsdEc.Value := dE;
2632
  EDc := EB * dE / 100;
2633
  ClientDataSetIngredientsEDc.Value := OutputEnergy(EDc, RapMS, FormOptions.Expression, FormOptions.Energy);
2634
  if EDc = 0
2635
  then // Division par 0
2636
  begin
2637
    ClientDataSetIngredientsEMc_EDc.Clear;
2638
    ClientDataSetIngredientsEMc.Value := 0;
2639
    EM := 0;
2640
  end
2641
  else
2642
  begin
2643
    EM_ED := ClientDataSetInraAfzEMc_EDc.Value;
2644
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2645
    then
2646
      DiffMAT := 0
2647
    else
2648
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2649
    if DiffMAT <> 0
2650
    then // Correction : variation de l'azote
2651
      EM_ED := EM_ED - 31.0 * 0.4 * DiffMAT / 6.25 / EDc;
2652
    ClientDataSetIngredientsEMc_EDc.Value := EM_ED * 100;
2653
    EM := EDc * EM_ED;
2654
    ClientDataSetIngredientsEMc.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2655
  end;
2656
  if EM = 0
2657
  then // Division par 0
2658
  begin
2659
    ClientDataSetIngredientsENc_EMc.Clear;
2660
    ClientDataSetIngredientsENc.Value := 0;
2661
  end
2662
  else
2663
  begin
2664
    EN_EM := ClientDataSetInraAfzENc_EMc.Value;
2665
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2666
    then
2667
      DiffMAT := 0
2668
    else
2669
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2670
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2671
    then
2672
      DiffMG := 0
2673
    else
2674
      DiffMG := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value;
2675
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2676
    then
2677
      DiffAmidon := 0
2678
    else
2679
      DiffAmidon := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - ClientDataSetInraAfzAmidon.Value;
2680
    if (DiffMAT <> 0) or (DiffMG <> 0) or (DiffAmidon <> 0)
2681
    then // Correction : variation MAT et/ou MG et/ou Amidon
2682
      EN_EM := EN_EM + (-2.8 * DiffMAT + 5.5 * DiffMG + 1.5 * DiffAmidon) / EM;
2683
    ClientDataSetIngredientsENc_EMc.Value := EN_EM * 100;
2684
    ClientDataSetIngredientsENc.Value := OutputEnergy(EM * EN_EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2685
  end;
2686
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MM'])
2687
  then
2688
    EDt := EDc + ClientDataSetInraAfza.Value * CALORIE * (1 - ClientDataSetInraAfzMM.Value) * (1 - ClientDataSetInraAfzb.Value * dE / 100)
2689
  else
2690
    EDt := EDc + ClientDataSetInraAfza.Value * CALORIE * (1 - TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MM'])) * (1 - ClientDataSetInraAfzb.Value * dE / 100);
2691
  ClientDataSetIngredientsEDt.Value := OutputEnergy(EDt, RapMS, FormOptions.Expression, FormOptions.Energy);
2692
  if EDc = 0
2693
  then // Division par 0
2694
    ClientDataSetIngredientsEDt_EDc.Clear
2695
  else
2696
    ClientDataSetIngredientsEDt_EDc.Value := EDt / EDc * 100;
2697
  if EDt = 0
2698
  then // Division par 0
2699
  begin
2700
    ClientDataSetIngredientsEMt_EDt.Clear;
2701
    ClientDataSetIngredientsEMt.Value := 0;
2702
    EM := 0;
2703
  end
2704
  else
2705
  begin
2706
    EM_ED := ClientDataSetInraAfzEMt_EDt.Value;
2707
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2708
    then
2709
      DiffMAT := 0
2710
    else
2711
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2712
    if DiffMAT <> 0
2713
    then // Correction : variation de l'azote
2714
      EM_ED := EM_ED - 31.0 * 0.4 * DiffMAT / 6.25 / EDt;
2715
    ClientDataSetIngredientsEMt_EDt.Value := EM_ED * 100;
2716
    EM := EDt * EM_ED;
2717
    ClientDataSetIngredientsEMt.Value := OutputEnergy(EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2718
  end;
2719
  if EM = 0
2720
  then // Division par 0
2721
  begin
2722
    ClientDataSetIngredientsENt_EMt.Clear;
2723
    ClientDataSetIngredientsENt.Value := 0;
2724
  end
2725
  else
2726
  begin
2727
    EN_EM := ClientDataSetInraAfzENt_EMt.Value;
2728
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2729
    then
2730
      DiffMAT := 0
2731
    else
2732
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2733
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MG'])
2734
    then
2735
      DiffMG := 0
2736
    else
2737
      DiffMG := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MG']) - ClientDataSetInraAfzMG.Value;
2738
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Amidon'])
2739
    then
2740
      DiffAmidon := 0
2741
    else
2742
      DiffAmidon := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Amidon']) - ClientDataSetInraAfzAmidon.Value;
2743
    if (DiffMAT <> 0) or (DiffMG <> 0) or (DiffAmidon <> 0)
2744
    then // Correction : variation MAT et/ou MG et/ou Amidon
2745
      EN_EM := EN_EM + (-2.8 * DiffMAT + 5.5 * DiffMG + 1.5 * DiffAmidon) / EM;
2746
    ClientDataSetIngredientsENt_EMt.Value := EN_EM * 100;
2747
    ClientDataSetIngredientsENt.Value := OutputEnergy(EM * EN_EM, RapMS, FormOptions.Expression, FormOptions.Energy);
2748
  end;
2749
  if ClientDataSetIngredientsEB.Value = 0
2750
  then
2751
    ClientDataSetIngredientsdEt.Clear
2752
  else
2753
    ClientDataSetIngredientsdEt.Value := ClientDataSetIngredientsEDt.Value / ClientDataSetIngredientsEB.Value * 100;
2754
  if ClientDataSetIngredientsEMc.Value = 0
2755
  then
2756
    ClientDataSetIngredientsEMt_EMc.Clear
2757
  else
2758
    ClientDataSetIngredientsEMt_EMc.Value := ClientDataSetIngredientsEMt.Value / ClientDataSetIngredientsEMc.Value * 100;
2759
  if ClientDataSetIngredientsENc.Value = 0
2760
  then
2761
    ClientDataSetIngredientsENt_ENc.Clear
2762
  else
2763
    ClientDataSetIngredientsENt_ENc.Value := ClientDataSetIngredientsENt.Value / ClientDataSetIngredientsENc.Value * 100;
2764
  // Digestibilit? f?cale de l'azote
2765
  if ClientDataSetInraAfzdNc.IsNull
2766
  then
2767
    ClientDataSetIngredientsdNc.Clear
2768
  else
2769
  begin
2770
    dN := ClientDataSetInraAfzdNc.Value * 100;
2771
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2772
    then
2773
      DiffMAT := 0
2774
    else
2775
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2776
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2777
    then
2778
      CorrCB := 0
2779
    else
2780
      CorrCB := 69.0 * DiffMAT - 122.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value);
2781
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2782
    then
2783
      CorrNDF := 0
2784
    else
2785
      CorrNDF := 79.0 * DiffMAT - 69.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value);
2786
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2787
    then
2788
      CorrADF := 0
2789
    else
2790
      CorrADF := 70.0 * DiffMAT - 116.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value);
2791
    Nb := 0;
2792
    if CorrCB <> 0 then Inc(Nb);
2793
    if CorrNDF <> 0 then Inc(Nb);
2794
    if CorrADF <> 0 then Inc(Nb);
2795
    if Nb > 0
2796
    then // Correction : moyenne des ?quations significatives
2797
      dN := dN + (CorrCB + CorrNDF + CorrADF) / Nb;
2798
    ClientDataSetIngredientsdNc.Value := dN;
2799
  end;
2800
  if ClientDataSetInraAfzdNt.IsNull
2801
  then
2802
    ClientDataSetIngredientsdNt.Clear
2803
  else
2804
  begin
2805
    dN := ClientDataSetInraAfzdNt.Value * 100;
2806
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MAT'])
2807
    then
2808
      DiffMAT := 0
2809
    else
2810
      DiffMAT := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MAT']) - ClientDataSetInraAfzMAT.Value;
2811
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['CB'])
2812
    then
2813
      CorrCB := 0
2814
    else
2815
      CorrCB := 77.0 * DiffMAT - 87.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['CB']) - ClientDataSetInraAfzCB.Value);
2816
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['NDF'])
2817
    then
2818
      CorrNDF := 0
2819
    else
2820
      CorrNDF := 86.0 * DiffMAT - 44.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['NDF']) - ClientDataSetInraAfzNDF.Value);
2821
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['ADF'])
2822
    then
2823
      CorrADF := 0
2824
    else
2825
      CorrADF := 78.0 * DiffMAT - 83.0 * (TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['ADF']) - ClientDataSetInraAfzADF.Value);
2826
    Nb := 0;
2827
    if CorrCB <> 0 then Inc(Nb);
2828
    if CorrNDF <> 0 then Inc(Nb);
2829
    if CorrADF <> 0 then Inc(Nb);
2830
    if Nb > 0
2831
    then // Correction : moyenne des ?quations significatives
2832
      dN := dN + (CorrCB + CorrNDF + CorrADF) / Nb;
2833
    ClientDataSetIngredientsdNt.Value := dN;
2834
  end;
2835
  // Acides amin?s
2836
  if RapMAT = 0
2837
  then // En l'absence de MAT, il n'y a pas d'acides amin?s
2838
  begin
2839
    // Teneurs
2840
    ClientDataSetIngredientsLys.Value := 0;
2841
    ClientDataSetIngredientsThr.Value := 0;
2842
    ClientDataSetIngredientsMet.Value := 0;
2843
    ClientDataSetIngredientsCys.Value := 0;
2844
    ClientDataSetIngredientsMetCys.Value := 0;
2845
    ClientDataSetIngredientsTrp.Value := 0;
2846
    ClientDataSetIngredientsIle.Value := 0;
2847
    ClientDataSetIngredientsVal.Value := 0;
2848
    ClientDataSetIngredientsLeu.Value := 0;
2849
    ClientDataSetIngredientsPhe.Value := 0;
2850
    ClientDataSetIngredientsTyr.Value := 0;
2851
    ClientDataSetIngredientsPheTyr.Value := 0;
2852
    ClientDataSetIngredientsHis.Value := 0;
2853
    ClientDataSetIngredientsArg.Value := 0;
2854
    ClientDataSetIngredientsAla.Value := 0;
2855
    ClientDataSetIngredientsAsp.Value := 0;
2856
    ClientDataSetIngredientsGlu.Value := 0;
2857
    ClientDataSetIngredientsGly.Value := 0;
2858
    ClientDataSetIngredientsSer.Value := 0;
2859
    ClientDataSetIngredientsPro.Value := 0;
2860
    // % MAT
2861
    ClientDataSetIngredientsLys_MAT.Clear;
2862
    ClientDataSetIngredientsThr_MAT.Clear;
2863
    ClientDataSetIngredientsMet_MAT.Clear;
2864
    ClientDataSetIngredientsCys_MAT.Clear;
2865
    ClientDataSetIngredientsMetCys_MAT.Clear;
2866
    ClientDataSetIngredientsTrp_MAT.Clear;
2867
    ClientDataSetIngredientsIle_MAT.Clear;
2868
    ClientDataSetIngredientsVal_MAT.Clear;
2869
    ClientDataSetIngredientsLeu_MAT.Clear;
2870
    ClientDataSetIngredientsPhe_MAT.Clear;
2871
    ClientDataSetIngredientsTyr_MAT.Clear;
2872
    ClientDataSetIngredientsPheTyr_MAT.Clear;
2873
    ClientDataSetIngredientsHis_MAT.Clear;
2874
    ClientDataSetIngredientsArg_MAT.Clear;
2875
    ClientDataSetIngredientsAla_MAT.Clear;
2876
    ClientDataSetIngredientsAsp_MAT.Clear;
2877
    ClientDataSetIngredientsGlu_MAT.Clear;
2878
    ClientDataSetIngredientsGly_MAT.Clear;
2879
    ClientDataSetIngredientsSer_MAT.Clear;
2880
    ClientDataSetIngredientsPro_MAT.Clear;
2881
    // Digestibilit?s
2882
    ClientDataSetIngredientsdLys.Clear;
2883
    ClientDataSetIngredientsdThr.Clear;
2884
    ClientDataSetIngredientsdMet.Clear;
2885
    ClientDataSetIngredientsdCys.Clear;
2886
    ClientDataSetIngredientsdMetCys.Clear;
2887
    ClientDataSetIngredientsdTrp.Clear;
2888
    ClientDataSetIngredientsdIle.Clear;
2889
    ClientDataSetIngredientsdVal.Clear;
2890
    ClientDataSetIngredientsdLeu.Clear;
2891
    ClientDataSetIngredientsdPhe.Clear;
2892
    ClientDataSetIngredientsdTyr.Clear;
2893
    ClientDataSetIngredientsdPheTyr.Clear;
2894
    ClientDataSetIngredientsdHis.Clear;
2895
    ClientDataSetIngredientsdArg.Clear;
2896
    ClientDataSetIngredientsdAla.Clear;
2897
    ClientDataSetIngredientsdAsp.Clear;
2898
    ClientDataSetIngredientsdGlu.Clear;
2899
    ClientDataSetIngredientsdGly.Clear;
2900
    ClientDataSetIngredientsdSer.Clear;
2901
    ClientDataSetIngredientsdPro.Clear;
2902
    // Teneurs digestibles
2903
    ClientDataSetIngredientsLysd.Value := 0;
2904
    ClientDataSetIngredientsThrd.Value := 0;
2905
    ClientDataSetIngredientsMetd.Value := 0;
2906
    ClientDataSetIngredientsCysd.Value := 0;
2907
    ClientDataSetIngredientsMetCysd.Value := 0;
2908
    ClientDataSetIngredientsTrpd.Value := 0;
2909
    ClientDataSetIngredientsIled.Value := 0;
2910
    ClientDataSetIngredientsVald.Value := 0;
2911
    ClientDataSetIngredientsLeud.Value := 0;
2912
    ClientDataSetIngredientsPhed.Value := 0;
2913
    ClientDataSetIngredientsTyrd.Value := 0;
2914
    ClientDataSetIngredientsPheTyrd.Value := 0;
2915
    ClientDataSetIngredientsHisd.Value := 0;
2916
    ClientDataSetIngredientsArgd.Value := 0;
2917
    ClientDataSetIngredientsAlad.Value := 0;
2918
    ClientDataSetIngredientsAspd.Value := 0;
2919
    ClientDataSetIngredientsGlud.Value := 0;
2920
    ClientDataSetIngredientsGlyd.Value := 0;
2921
    ClientDataSetIngredientsSerd.Value := 0;
2922
    ClientDataSetIngredientsProd.Value := 0;
2923
  end
2924
  else
2925
  begin
2926
    // Lys
2927
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
2928
    and (ClientDataSetInraAfzLys.Value = 0)
2929
    then
2930
    begin
2931
      ClientDataSetIngredientsLys.Value := 0;
2932
      ClientDataSetIngredientsLys_MAT.Clear;
2933
      ClientDataSetIngredientsdLys.Clear;
2934
      ClientDataSetIngredientsLysd.Value := 0;
2935
    end
2936
    else
2937
    begin
2938
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Lys'])
2939
      then
2940
        ClientDataSetIngredientsLys.Value := OutputAA(ClientDataSetInraAfzLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2941
      else
2942
        ClientDataSetIngredientsLys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Lys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2943
      if ClientDataSetIngredientsLys.Value = 0
2944
      then
2945
        ClientDataSetIngredientsLys_MAT.Clear
2946
      else
2947
        ClientDataSetIngredientsLys_MAT.Value := InputAA(ClientDataSetIngredientsLys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2948
      if ClientDataSetInraAfzdLys.IsNull
2949
      then
2950
        ClientDataSetIngredientsdLys.Value := dLys * 100
2951
      else
2952
        ClientDataSetIngredientsdLys.Value := ClientDataSetInraAfzdLys.Value * 100;
2953
      ClientDataSetIngredientsLysd.Value := ClientDataSetIngredientsdLys.Value / 100 * ClientDataSetIngredientsLys.Value;
2954
    end;
2955
    // Thr
2956
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
2957
    and (ClientDataSetInraAfzThr.Value = 0)
2958
    then
2959
    begin
2960
      ClientDataSetIngredientsThr.Value := 0;
2961
      ClientDataSetIngredientsThr_MAT.Clear;
2962
      ClientDataSetIngredientsdThr.Clear;
2963
      ClientDataSetIngredientsThrd.Value := 0;
2964
    end
2965
    else
2966
    begin
2967
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Thr'])
2968
      then
2969
        ClientDataSetIngredientsThr.Value := OutputAA(ClientDataSetInraAfzThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2970
      else
2971
        ClientDataSetIngredientsThr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Thr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
2972
      if ClientDataSetIngredientsThr.Value = 0
2973
      then
2974
        ClientDataSetIngredientsThr_MAT.Clear
2975
      else
2976
        ClientDataSetIngredientsThr_MAT.Value := InputAA(ClientDataSetIngredientsThr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
2977
      if ClientDataSetInraAfzdThr.IsNull
2978
      then
2979
        ClientDataSetIngredientsdThr.Value := dThr * 100
2980
      else
2981
        ClientDataSetIngredientsdThr.Value := ClientDataSetInraAfzdThr.Value * 100;
2982
      ClientDataSetIngredientsThrd.Value := ClientDataSetIngredientsdThr.Value / 100 * ClientDataSetIngredientsThr.Value;
2983
    end;
2984
    // Met
2985
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
2986
    and (ClientDataSetInraAfzMet.Value = 0)
2987
    then
2988
    begin
2989
      ClientDataSetIngredientsMet.Value := 0;
2990
      ClientDataSetIngredientsMet_MAT.Clear;
2991
      ClientDataSetIngredientsdMet.Clear;
2992
      ClientDataSetIngredientsMetd.Value := 0;
2993
    end
2994
    else
2995
    begin
2996
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Met'])
2997
      then
2998
        ClientDataSetIngredientsMet.Value := OutputAA(ClientDataSetInraAfzMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
2999
      else
3000
        ClientDataSetIngredientsMet.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Met']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3001
      if ClientDataSetIngredientsMet.Value = 0
3002
      then
3003
        ClientDataSetIngredientsMet_MAT.Clear
3004
      else
3005
        ClientDataSetIngredientsMet_MAT.Value := InputAA(ClientDataSetIngredientsMet.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3006
      if ClientDataSetInraAfzdMet.IsNull
3007
      then
3008
        ClientDataSetIngredientsdMet.Value := dMet * 100
3009
      else
3010
        ClientDataSetIngredientsdMet.Value := ClientDataSetInraAfzdMet.Value * 100;
3011
      ClientDataSetIngredientsMetd.Value := ClientDataSetIngredientsdMet.Value / 100 * ClientDataSetIngredientsMet.Value;
3012
    end;
3013
    // Cys
3014
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
3015
    and (ClientDataSetInraAfzCys.Value = 0)
3016
    then
3017
    begin
3018
      ClientDataSetIngredientsCys.Value := 0;
3019
      ClientDataSetIngredientsCys_MAT.Clear;
3020
      ClientDataSetIngredientsdCys.Clear;
3021
      ClientDataSetIngredientsCysd.Value := 0;
3022
    end
3023
    else
3024
    begin
3025
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cys'])
3026
      then
3027
        ClientDataSetIngredientsCys.Value := OutputAA(ClientDataSetInraAfzCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3028
      else
3029
        ClientDataSetIngredientsCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3030
      if ClientDataSetIngredientsCys.Value = 0
3031
      then
3032
        ClientDataSetIngredientsCys_MAT.Clear
3033
      else
3034
        ClientDataSetIngredientsCys_MAT.Value := InputAA(ClientDataSetIngredientsCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3035
      if ClientDataSetInraAfzdCys.IsNull
3036
      then
3037
        ClientDataSetIngredientsdCys.Value := dCys * 100
3038
      else
3039
        ClientDataSetIngredientsdCys.Value := ClientDataSetInraAfzdCys.Value * 100;
3040
      ClientDataSetIngredientsCysd.Value := ClientDataSetIngredientsdCys.Value / 100 * ClientDataSetIngredientsCys.Value;
3041
    end;
3042
    // Met + Cys
3043
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
3044
    and (ClientDataSetInraAfzMetCys.Value = 0)
3045
    then
3046
    begin
3047
      ClientDataSetIngredientsMetCys.Value := 0;
3048
      ClientDataSetIngredientsMetCys_MAT.Clear;
3049
      ClientDataSetIngredientsdMetCys.Clear;
3050
      ClientDataSetIngredientsMetCysd.Value := 0;
3051
    end
3052
    else
3053
    begin
3054
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['MetCys'])
3055
      then
3056
        ClientDataSetIngredientsMetCys.Value := OutputAA(ClientDataSetInraAfzMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3057
      else
3058
        ClientDataSetIngredientsMetCys.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['MetCys']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3059
      if ClientDataSetIngredientsMetCys.Value = 0
3060
      then
3061
        ClientDataSetIngredientsMetCys_MAT.Clear
3062
      else
3063
        ClientDataSetIngredientsMetCys_MAT.Value := InputAA(ClientDataSetIngredientsMetCys.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3064
      if ClientDataSetInraAfzdMetCys.IsNull
3065
      then
3066
        ClientDataSetIngredientsdMetCys.Value := dMetCys * 100
3067
      else
3068
        ClientDataSetIngredientsdMetCys.Value := ClientDataSetInraAfzdMetCys.Value * 100;
3069
      ClientDataSetIngredientsMetCysd.Value := ClientDataSetIngredientsdMetCys.Value / 100 * ClientDataSetIngredientsMetCys.Value;
3070
    end;
3071
    // Trp
3072
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
3073
    and (ClientDataSetInraAfzTrp.Value = 0)
3074
    then
3075
    begin
3076
      ClientDataSetIngredientsTrp.Value := 0;
3077
      ClientDataSetIngredientsTrp_MAT.Clear;
3078
      ClientDataSetIngredientsdTrp.Clear;
3079
      ClientDataSetIngredientsTrpd.Value := 0;
3080
    end
3081
    else
3082
    begin
3083
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Trp'])
3084
      then
3085
        ClientDataSetIngredientsTrp.Value := OutputAA(ClientDataSetInraAfzTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3086
      else
3087
        ClientDataSetIngredientsTrp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Trp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3088
      if ClientDataSetIngredientsTrp.Value = 0
3089
      then
3090
        ClientDataSetIngredientsTrp_MAT.Clear
3091
      else
3092
        ClientDataSetIngredientsTrp_MAT.Value := InputAA(ClientDataSetIngredientsTrp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3093
      if ClientDataSetInraAfzdTrp.IsNull
3094
      then
3095
        ClientDataSetIngredientsdTrp.Value := dTrp * 100
3096
      else
3097
        ClientDataSetIngredientsdTrp.Value := ClientDataSetInraAfzdTrp.Value * 100;
3098
      ClientDataSetIngredientsTrpd.Value := ClientDataSetIngredientsdTrp.Value / 100 * ClientDataSetIngredientsTrp.Value;
3099
    end;
3100
    // Ile
3101
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
3102
    and (ClientDataSetInraAfzIle.Value = 0)
3103
    then
3104
    begin
3105
      ClientDataSetIngredientsIle.Value := 0;
3106
      ClientDataSetIngredientsIle_MAT.Clear;
3107
      ClientDataSetIngredientsdIle.Clear;
3108
      ClientDataSetIngredientsIled.Value := 0;
3109
    end
3110
    else
3111
    begin
3112
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ile'])
3113
      then
3114
        ClientDataSetIngredientsIle.Value := OutputAA(ClientDataSetInraAfzIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3115
      else
3116
        ClientDataSetIngredientsIle.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ile']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3117
      if ClientDataSetIngredientsIle.Value = 0
3118
      then
3119
        ClientDataSetIngredientsIle_MAT.Clear
3120
      else
3121
        ClientDataSetIngredientsIle_MAT.Value := InputAA(ClientDataSetIngredientsIle.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3122
      if ClientDataSetInraAfzdIle.IsNull
3123
      then
3124
        ClientDataSetIngredientsdIle.Value := dIle * 100
3125
      else
3126
        ClientDataSetIngredientsdIle.Value := ClientDataSetInraAfzdIle.Value * 100;
3127
      ClientDataSetIngredientsIled.Value := ClientDataSetIngredientsdIle.Value / 100 * ClientDataSetIngredientsIle.Value;
3128
    end;
3129
    // Val
3130
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
3131
    and (ClientDataSetInraAfzVal.Value = 0)
3132
    then
3133
    begin
3134
      ClientDataSetIngredientsVal.Value := 0;
3135
      ClientDataSetIngredientsVal_MAT.Clear;
3136
      ClientDataSetIngredientsdVal.Clear;
3137
      ClientDataSetIngredientsVald.Value := 0;
3138
    end
3139
    else
3140
    begin
3141
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Val'])
3142
      then
3143
        ClientDataSetIngredientsVal.Value := OutputAA(ClientDataSetInraAfzVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3144
      else
3145
        ClientDataSetIngredientsVal.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Val']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3146
      if ClientDataSetIngredientsVal.Value = 0
3147
      then
3148
        ClientDataSetIngredientsVal_MAT.Clear
3149
      else
3150
        ClientDataSetIngredientsVal_MAT.Value := InputAA(ClientDataSetIngredientsVal.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3151
      if ClientDataSetInraAfzdVal.IsNull
3152
      then
3153
        ClientDataSetIngredientsdVal.Value := dVal * 100
3154
      else
3155
        ClientDataSetIngredientsdVal.Value := ClientDataSetInraAfzdVal.Value * 100;
3156
      ClientDataSetIngredientsVald.Value := ClientDataSetIngredientsdVal.Value / 100 * ClientDataSetIngredientsVal.Value;
3157
    end;
3158
    // Leu
3159
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
3160
    and (ClientDataSetInraAfzLeu.Value = 0)
3161
    then
3162
    begin
3163
      ClientDataSetIngredientsLeu.Value := 0;
3164
      ClientDataSetIngredientsLeu_MAT.Clear;
3165
      ClientDataSetIngredientsdLeu.Clear;
3166
      ClientDataSetIngredientsLeud.Value := 0;
3167
    end
3168
    else
3169
    begin
3170
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Leu'])
3171
      then
3172
        ClientDataSetIngredientsLeu.Value := OutputAA(ClientDataSetInraAfzLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3173
      else
3174
        ClientDataSetIngredientsLeu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Leu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3175
      if ClientDataSetIngredientsLeu.Value = 0
3176
      then
3177
        ClientDataSetIngredientsLeu_MAT.Clear
3178
      else
3179
        ClientDataSetIngredientsLeu_MAT.Value := InputAA(ClientDataSetIngredientsLeu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3180
      if ClientDataSetInraAfzdLeu.IsNull
3181
      then
3182
        ClientDataSetIngredientsdLeu.Value := dLeu * 100
3183
      else
3184
        ClientDataSetIngredientsdLeu.Value := ClientDataSetInraAfzdLeu.Value * 100;
3185
      ClientDataSetIngredientsLeud.Value := ClientDataSetIngredientsdLeu.Value / 100 * ClientDataSetIngredientsLeu.Value;
3186
    end;
3187
    // Phe
3188
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
3189
    and (ClientDataSetInraAfzPhe.Value = 0)
3190
    then
3191
    begin
3192
      ClientDataSetIngredientsPhe.Value := 0;
3193
      ClientDataSetIngredientsPhe_MAT.Clear;
3194
      ClientDataSetIngredientsdPhe.Clear;
3195
      ClientDataSetIngredientsPhed.Value := 0;
3196
    end
3197
    else
3198
    begin
3199
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Phe'])
3200
      then
3201
        ClientDataSetIngredientsPhe.Value := OutputAA(ClientDataSetInraAfzPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3202
      else
3203
        ClientDataSetIngredientsPhe.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Phe']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3204
      if ClientDataSetIngredientsPhe.Value = 0
3205
      then
3206
        ClientDataSetIngredientsPhe_MAT.Clear
3207
      else
3208
        ClientDataSetIngredientsPhe_MAT.Value := InputAA(ClientDataSetIngredientsPhe.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3209
      if ClientDataSetInraAfzdPhe.IsNull
3210
      then
3211
        ClientDataSetIngredientsdPhe.Value := dPhe * 100
3212
      else
3213
        ClientDataSetIngredientsdPhe.Value := ClientDataSetInraAfzdPhe.Value * 100;
3214
      ClientDataSetIngredientsPhed.Value := ClientDataSetIngredientsdPhe.Value / 100 * ClientDataSetIngredientsPhe.Value;
3215
    end;
3216
    // Tyr
3217
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
3218
    and (ClientDataSetInraAfzTyr.Value = 0)
3219
    then
3220
    begin
3221
      ClientDataSetIngredientsTyr.Value := 0;
3222
      ClientDataSetIngredientsTyr_MAT.Clear;
3223
      ClientDataSetIngredientsdTyr.Clear;
3224
      ClientDataSetIngredientsTyrd.Value := 0;
3225
    end
3226
    else
3227
    begin
3228
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Tyr'])
3229
      then
3230
        ClientDataSetIngredientsTyr.Value := OutputAA(ClientDataSetInraAfzTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3231
      else
3232
        ClientDataSetIngredientsTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Tyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3233
      if ClientDataSetIngredientsTyr.Value = 0
3234
      then
3235
        ClientDataSetIngredientsTyr_MAT.Clear
3236
      else
3237
        ClientDataSetIngredientsTyr_MAT.Value := InputAA(ClientDataSetIngredientsTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3238
      if ClientDataSetInraAfzdTyr.IsNull
3239
      then
3240
        ClientDataSetIngredientsdTyr.Value := dTyr * 100
3241
      else
3242
        ClientDataSetIngredientsdTyr.Value := ClientDataSetInraAfzdTyr.Value * 100;
3243
      ClientDataSetIngredientsTyrd.Value := ClientDataSetIngredientsdTyr.Value / 100 * ClientDataSetIngredientsTyr.Value;
3244
    end;
3245
    // Phe + Tyr
3246
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
3247
    and (ClientDataSetInraAfzPheTyr.Value = 0)
3248
    then
3249
    begin
3250
      ClientDataSetIngredientsPheTyr.Value := 0;
3251
      ClientDataSetIngredientsPheTyr_MAT.Clear;
3252
      ClientDataSetIngredientsdPheTyr.Clear;
3253
      ClientDataSetIngredientsPheTyrd.Value := 0;
3254
    end
3255
    else
3256
    begin
3257
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['PheTyr'])
3258
      then
3259
        ClientDataSetIngredientsPheTyr.Value := OutputAA(ClientDataSetInraAfzPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3260
      else
3261
        ClientDataSetIngredientsPheTyr.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['PheTyr']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3262
      if ClientDataSetIngredientsPheTyr.Value = 0
3263
      then
3264
        ClientDataSetIngredientsPheTyr_MAT.Clear
3265
      else
3266
        ClientDataSetIngredientsPheTyr_MAT.Value := InputAA(ClientDataSetIngredientsPheTyr.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3267
      if ClientDataSetInraAfzdPheTyr.IsNull
3268
      then
3269
        ClientDataSetIngredientsdPheTyr.Value := dPheTyr * 100
3270
      else
3271
        ClientDataSetIngredientsdPheTyr.Value := ClientDataSetInraAfzdPheTyr.Value * 100;
3272
      ClientDataSetIngredientsPheTyrd.Value := ClientDataSetIngredientsdPheTyr.Value / 100 * ClientDataSetIngredientsPheTyr.Value;
3273
    end;
3274
    // His
3275
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
3276
    and (ClientDataSetInraAfzHis.Value = 0)
3277
    then
3278
    begin
3279
      ClientDataSetIngredientsHis.Value := 0;
3280
      ClientDataSetIngredientsHis_MAT.Clear;
3281
      ClientDataSetIngredientsdHis.Clear;
3282
      ClientDataSetIngredientsHisd.Value := 0;
3283
    end
3284
    else
3285
    begin
3286
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['His'])
3287
      then
3288
        ClientDataSetIngredientsHis.Value := OutputAA(ClientDataSetInraAfzHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3289
      else
3290
        ClientDataSetIngredientsHis.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['His']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3291
      if ClientDataSetIngredientsHis.Value = 0
3292
      then
3293
        ClientDataSetIngredientsHis_MAT.Clear
3294
      else
3295
        ClientDataSetIngredientsHis_MAT.Value := InputAA(ClientDataSetIngredientsHis.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3296
      if ClientDataSetInraAfzdHis.IsNull
3297
      then
3298
        ClientDataSetIngredientsdHis.Value := dHis * 100
3299
      else
3300
        ClientDataSetIngredientsdHis.Value := ClientDataSetInraAfzdHis.Value * 100;
3301
      ClientDataSetIngredientsHisd.Value := ClientDataSetIngredientsdHis.Value / 100 * ClientDataSetIngredientsHis.Value;
3302
    end;
3303
    // Arg
3304
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
3305
    and (ClientDataSetInraAfzArg.Value = 0)
3306
    then
3307
    begin
3308
      ClientDataSetIngredientsArg.Value := 0;
3309
      ClientDataSetIngredientsArg_MAT.Clear;
3310
      ClientDataSetIngredientsdArg.Clear;
3311
      ClientDataSetIngredientsArgd.Value := 0;
3312
    end
3313
    else
3314
    begin
3315
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Arg'])
3316
      then
3317
        ClientDataSetIngredientsArg.Value := OutputAA(ClientDataSetInraAfzArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3318
      else
3319
        ClientDataSetIngredientsArg.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Arg']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3320
      if ClientDataSetIngredientsArg.Value = 0
3321
      then
3322
        ClientDataSetIngredientsArg_MAT.Clear
3323
      else
3324
        ClientDataSetIngredientsArg_MAT.Value := InputAA(ClientDataSetIngredientsArg.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3325
      if ClientDataSetInraAfzdArg.IsNull
3326
      then
3327
        ClientDataSetIngredientsdArg.Value := dArg * 100
3328
      else
3329
        ClientDataSetIngredientsdArg.Value := ClientDataSetInraAfzdArg.Value * 100;
3330
      ClientDataSetIngredientsArgd.Value := ClientDataSetIngredientsdArg.Value / 100 * ClientDataSetIngredientsArg.Value;
3331
    end;
3332
    // Ala
3333
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
3334
    and (ClientDataSetInraAfzAla.Value = 0)
3335
    then
3336
    begin
3337
      ClientDataSetIngredientsAla.Value := 0;
3338
      ClientDataSetIngredientsAla_MAT.Clear;
3339
      ClientDataSetIngredientsdAla.Clear;
3340
      ClientDataSetIngredientsAlad.Value := 0;
3341
    end
3342
    else
3343
    begin
3344
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ala'])
3345
      then
3346
        ClientDataSetIngredientsAla.Value := OutputAA(ClientDataSetInraAfzAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3347
      else
3348
        ClientDataSetIngredientsAla.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ala']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3349
      if ClientDataSetIngredientsAla.Value = 0
3350
      then
3351
        ClientDataSetIngredientsAla_MAT.Clear
3352
      else
3353
        ClientDataSetIngredientsAla_MAT.Value := InputAA(ClientDataSetIngredientsAla.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3354
      if ClientDataSetInraAfzdAla.IsNull
3355
      then
3356
        ClientDataSetIngredientsdAla.Value := dAla * 100
3357
      else
3358
        ClientDataSetIngredientsdAla.Value := ClientDataSetInraAfzdAla.Value * 100;
3359
      ClientDataSetIngredientsAlad.Value := ClientDataSetIngredientsdAla.Value / 100 * ClientDataSetIngredientsAla.Value;
3360
    end;
3361
    // Asp
3362
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
3363
    and (ClientDataSetInraAfzAsp.Value = 0)
3364
    then
3365
    begin
3366
      ClientDataSetIngredientsAsp.Value := 0;
3367
      ClientDataSetIngredientsAsp_MAT.Clear;
3368
      ClientDataSetIngredientsdAsp.Clear;
3369
      ClientDataSetIngredientsAspd.Value := 0;
3370
    end
3371
    else
3372
    begin
3373
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Asp'])
3374
      then
3375
        ClientDataSetIngredientsAsp.Value := OutputAA(ClientDataSetInraAfzAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3376
      else
3377
        ClientDataSetIngredientsAsp.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Asp']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3378
      if ClientDataSetIngredientsAsp.Value = 0
3379
      then
3380
        ClientDataSetIngredientsAsp_MAT.Clear
3381
      else
3382
        ClientDataSetIngredientsAsp_MAT.Value := InputAA(ClientDataSetIngredientsAsp.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3383
      if ClientDataSetInraAfzdAsp.IsNull
3384
      then
3385
        ClientDataSetIngredientsdAsp.Value := dAsp * 100
3386
      else
3387
        ClientDataSetIngredientsdAsp.Value := ClientDataSetInraAfzdAsp.Value * 100;
3388
      ClientDataSetIngredientsAspd.Value := ClientDataSetIngredientsdAsp.Value / 100 * ClientDataSetIngredientsAsp.Value;
3389
    end;
3390
    // Glu
3391
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
3392
    and (ClientDataSetInraAfzGlu.Value = 0)
3393
    then
3394
    begin
3395
      ClientDataSetIngredientsGlu.Value := 0;
3396
      ClientDataSetIngredientsGlu_MAT.Clear;
3397
      ClientDataSetIngredientsdGlu.Clear;
3398
      ClientDataSetIngredientsGlud.Value := 0;
3399
    end
3400
    else
3401
    begin
3402
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Glu'])
3403
      then
3404
        ClientDataSetIngredientsGlu.Value := OutputAA(ClientDataSetInraAfzGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3405
      else
3406
        ClientDataSetIngredientsGlu.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Glu']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3407
      if ClientDataSetIngredientsGlu.Value = 0
3408
      then
3409
        ClientDataSetIngredientsGlu_MAT.Clear
3410
      else
3411
        ClientDataSetIngredientsGlu_MAT.Value := InputAA(ClientDataSetIngredientsGlu.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3412
      if ClientDataSetInraAfzdGlu.IsNull
3413
      then
3414
        ClientDataSetIngredientsdGlu.Value := dGlu * 100
3415
      else
3416
        ClientDataSetIngredientsdGlu.Value := ClientDataSetInraAfzdGlu.Value * 100;
3417
      ClientDataSetIngredientsGlud.Value := ClientDataSetIngredientsdGlu.Value / 100 * ClientDataSetIngredientsGlu.Value;
3418
    end;
3419
    // Gly
3420
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
3421
    and (ClientDataSetInraAfzGly.Value = 0)
3422
    then
3423
    begin
3424
      ClientDataSetIngredientsGly.Value := 0;
3425
      ClientDataSetIngredientsGly_MAT.Clear;
3426
      ClientDataSetIngredientsdGly.Clear;
3427
      ClientDataSetIngredientsGlyd.Value := 0;
3428
    end
3429
    else
3430
    begin
3431
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Gly'])
3432
      then
3433
        ClientDataSetIngredientsGly.Value := OutputAA(ClientDataSetInraAfzGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3434
      else
3435
        ClientDataSetIngredientsGly.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Gly']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3436
      if ClientDataSetIngredientsGly.Value = 0
3437
      then
3438
        ClientDataSetIngredientsGly_MAT.Clear
3439
      else
3440
        ClientDataSetIngredientsGly_MAT.Value := InputAA(ClientDataSetIngredientsGly.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3441
      if ClientDataSetInraAfzdGly.IsNull
3442
      then
3443
        ClientDataSetIngredientsdGly.Value := dGly * 100
3444
      else
3445
        ClientDataSetIngredientsdGly.Value := ClientDataSetInraAfzdGly.Value * 100;
3446
      ClientDataSetIngredientsGlyd.Value := ClientDataSetIngredientsdGly.Value / 100 * ClientDataSetIngredientsGly.Value;
3447
    end;
3448
    // Ser
3449
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
3450
    and (ClientDataSetInraAfzSer.Value = 0)
3451
    then
3452
    begin
3453
      ClientDataSetIngredientsSer.Value := 0;
3454
      ClientDataSetIngredientsSer_MAT.Clear;
3455
      ClientDataSetIngredientsdSer.Clear;
3456
      ClientDataSetIngredientsSerd.Value := 0;
3457
    end
3458
    else
3459
    begin
3460
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ser'])
3461
      then
3462
        ClientDataSetIngredientsSer.Value := OutputAA(ClientDataSetInraAfzSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3463
      else
3464
        ClientDataSetIngredientsSer.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ser']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3465
      if ClientDataSetIngredientsSer.Value = 0
3466
      then
3467
        ClientDataSetIngredientsSer_MAT.Clear
3468
      else
3469
        ClientDataSetIngredientsSer_MAT.Value := InputAA(ClientDataSetIngredientsSer.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3470
      if ClientDataSetInraAfzdSer.IsNull
3471
      then
3472
        ClientDataSetIngredientsdSer.Value := dSer * 100
3473
      else
3474
        ClientDataSetIngredientsdSer.Value := ClientDataSetInraAfzdSer.Value * 100;
3475
      ClientDataSetIngredientsSerd.Value := ClientDataSetIngredientsdSer.Value / 100 * ClientDataSetIngredientsSer.Value;
3476
    end;
3477
    // Pro
3478
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
3479
    and (ClientDataSetInraAfzPro.Value = 0)
3480
    then
3481
    begin
3482
      ClientDataSetIngredientsPro.Value := 0;
3483
      ClientDataSetIngredientsPro_MAT.Clear;
3484
      ClientDataSetIngredientsdPro.Clear;
3485
      ClientDataSetIngredientsProd.Value := 0;
3486
    end
3487
    else
3488
    begin
3489
      if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Pro'])
3490
      then
3491
        ClientDataSetIngredientsPro.Value := OutputAA(ClientDataSetInraAfzPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA)
3492
      else
3493
        ClientDataSetIngredientsPro.Value := OutputAA(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Pro']), RapMAT, RapMS, FormOptions.Expression, FormOptions.AA);
3494
      if ClientDataSetIngredientsPro.Value = 0
3495
      then
3496
        ClientDataSetIngredientsPro_MAT.Clear
3497
      else
3498
        ClientDataSetIngredientsPro_MAT.Value := InputAA(ClientDataSetIngredientsPro.Value, RapMAT, RapMS, FormOptions.Expression, FormOptions.AA) * 100;
3499
      if ClientDataSetInraAfzdPro.IsNull
3500
      then
3501
        ClientDataSetIngredientsdPro.Value := dPro * 100
3502
      else
3503
        ClientDataSetIngredientsdPro.Value := ClientDataSetInraAfzdPro.Value * 100;
3504
      ClientDataSetIngredientsProd.Value := ClientDataSetIngredientsdPro.Value / 100 * ClientDataSetIngredientsPro.Value;
3505
    end;
3506
  end;
3507
  // Min?raux
3508
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Ca'])
3509
  then
3510
    ClientDataSetIngredientsCa.Value := OutputMinerals(ClientDataSetInraAfzCa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3511
  else
3512
    ClientDataSetIngredientsCa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Ca']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3513
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['P'])
3514
  then
3515
    ClientDataSetIngredientsP.Value := OutputMinerals(ClientDataSetInraAfzP.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3516
  else
3517
    ClientDataSetIngredientsP.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['P']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3518
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Na'])
3519
  then
3520
    ClientDataSetIngredientsNa.Value := OutputMinerals(ClientDataSetInraAfzNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3521
  else
3522
    ClientDataSetIngredientsNa.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Na']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3523
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['K'])
3524
  then
3525
    ClientDataSetIngredientsK.Value := OutputMinerals(ClientDataSetInraAfzK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3526
  else
3527
    ClientDataSetIngredientsK.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['K']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3528
  if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['Cl'])
3529
  then
3530
    ClientDataSetIngredientsCl.Value := OutputMinerals(ClientDataSetInraAfzCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals)
3531
  else
3532
    ClientDataSetIngredientsCl.Value := OutputMinerals(TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['Cl']), RapMS, FormOptions.Expression, FormOptions.Minerals);
3533
  ClientDataSetIngredientsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetIngredientsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetIngredientsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
3534
  if ClientDataSetIngredientsP.Value = 0
3535
  then // En l'absence de P, il n'y a pas de dP
3536
  begin
3537
    ClientDataSetIngredientsdP.Clear;
3538
    ClientDataSetIngredientsdPphy.Clear;
3539
  end
3540
  else
3541
  begin
3542
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dP'])
3543
    then
3544
      if ClientDataSetInraAfzdP.IsNull
3545
      then // Par d?faut dP = 20%
3546
        ClientDataSetIngredientsdP.Value := 20
3547
      else
3548
        ClientDataSetIngredientsdP.Value := ClientDataSetInraAfzdP.Value * 100
3549
    else
3550
      ClientDataSetIngredientsdP.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dP']) * 100;
3551
    if TableIngredients.FieldIsNull(TableIngredients.FieldIndex['dPphy'])
3552
    then
3553
      if ClientDataSetInraAfzdPphy.IsNull
3554
      then // Par d?faut dPphy = dP
3555
        ClientDataSetIngredientsdPphy.Value := ClientDataSetIngredientsdP.Value
3556
      else
3557
        ClientDataSetIngredientsdPphy.Value := ClientDataSetInraAfzdPphy.Value * 100
3558
    else
3559
      ClientDataSetIngredientsdPphy.Value := TableIngredients.FieldAsDouble(TableIngredients.FieldIndex['dPphy']) * 100;
3560
  end;
3561
  // Autres rapports
3562
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENc.IsNull or (ClientDataSetIngredientsENc.Value = 0)
3563
  then
3564
    ClientDataSetIngredientsLysd_ENc.Clear
3565
  else
3566
    if FormOptions.Energy = 0
3567
    then // g / MJ
3568
      if FormOptions.AA = 0
3569
      then // % (conversion)
3570
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value
3571
      else // g/kg
3572
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value
3573
    else // g / 1000 kcal
3574
      if FormOptions.AA = 0
3575
      then // % (conversion)
3576
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENc.Value * 1000
3577
      else // g/kg
3578
        ClientDataSetIngredientsLysd_ENc.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENc.Value * 1000;
3579
  if ClientDataSetIngredientsLysd.IsNull or ClientDataSetIngredientsENt.IsNull or (ClientDataSetIngredientsENt.Value = 0)
3580
  then
3581
    ClientDataSetIngredientsLysd_ENt.Clear
3582
  else
3583
    if FormOptions.Energy = 0
3584
    then // g / MJ
3585
      if FormOptions.AA = 0
3586
      then // % (conversion)
3587
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value
3588
      else // g/kg
3589
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value
3590
    else // g / 1000 kcal
3591
      if FormOptions.AA = 0
3592
      then // % (conversion)
3593
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / 100 * 1000 / ClientDataSetIngredientsENt.Value * 1000
3594
      else // g/kg
3595
        ClientDataSetIngredientsLysd_ENt.Value := ClientDataSetIngredientsLysd.Value / ClientDataSetIngredientsENt.Value * 1000;
3596
end;
3597

    
3598
procedure TDataModuleDeclaration.CalcFeed;
3599
// Renseigner l'enregistrement courant de ClientDataSetFeeds
3600
// ? partir de l'enregistrement courant de TableFeeds
3601
// en tenant compte des unit?s configur?es
3602
const
3603
  a = 1.026;
3604
  b = 0.00263;
3605
var
3606
  Ratio, CoefPhytase, PdEndo, PhytaseEndo, PhytaseMicro, PdMicro: Double;
3607
begin
3608
  if ClientDataSetComposition.RecordCount = 0
3609
  then // En l'absence de composition cent?simale toutes les valeurs sont nulles
3610
  begin
3611
    // Analyse proximale
3612
    ClientDataSetFeedsMS.Clear;
3613
    ClientDataSetFeedsMS2.Clear;
3614
    ClientDataSetFeedsMM.Clear;
3615
    ClientDataSetFeedsMAT.Clear;
3616
    ClientDataSetFeedsMG.Clear;
3617
    ClientDataSetFeedsCB.Clear;
3618
    ClientDataSetFeedsNDF.Clear;
3619
    ClientDataSetFeedsADF.Clear;
3620
    ClientDataSetFeedsADL.Clear;
3621
    ClientDataSetFeedsAmidon.Clear;
3622
    ClientDataSetFeedsSucres.Clear;
3623
    // Energie
3624
    ClientDataSetFeedsEB.Clear;
3625
    ClientDataSetFeedsEDc.Clear;
3626
    ClientDataSetFeedsEMc.Clear;
3627
    ClientDataSetFeedsENc.Clear;
3628
    ClientDataSetFeedsEDt.Clear;
3629
    ClientDataSetFeedsEMt.Clear;
3630
    ClientDataSetFeedsENt.Clear;
3631
    // Digestibilit? f?cale de l'azote
3632
    ClientDataSetFeedsdNc.Clear;
3633
    ClientDataSetFeedsdNt.Clear;
3634
    // Acides amin?s
3635
    ClientDataSetFeedsLys.Clear;
3636
    ClientDataSetFeedsThr.Clear;
3637
    ClientDataSetFeedsMet.Clear;
3638
    ClientDataSetFeedsCys.Clear;
3639
    ClientDataSetFeedsMetCys.Clear;
3640
    ClientDataSetFeedsTrp.Clear;
3641
    ClientDataSetFeedsIle.Clear;
3642
    ClientDataSetFeedsVal.Clear;
3643
    ClientDataSetFeedsLeu.Clear;
3644
    ClientDataSetFeedsPhe.Clear;
3645
    ClientDataSetFeedsTyr.Clear;
3646
    ClientDataSetFeedsPheTyr.Clear;
3647
    ClientDataSetFeedsHis.Clear;
3648
    ClientDataSetFeedsArg.Clear;
3649
    ClientDataSetFeedsAla.Clear;
3650
    ClientDataSetFeedsAsp.Clear;
3651
    ClientDataSetFeedsGlu.Clear;
3652
    ClientDataSetFeedsGly.Clear;
3653
    ClientDataSetFeedsSer.Clear;
3654
    ClientDataSetFeedsPro.Clear;
3655
    ClientDataSetFeedsLysd.Clear;
3656
    ClientDataSetFeedsThrd.Clear;
3657
    ClientDataSetFeedsMetd.Clear;
3658
    ClientDataSetFeedsCysd.Clear;
3659
    ClientDataSetFeedsMetCysd.Clear;
3660
    ClientDataSetFeedsTrpd.Clear;
3661
    ClientDataSetFeedsIled.Clear;
3662
    ClientDataSetFeedsVald.Clear;
3663
    ClientDataSetFeedsLeud.Clear;
3664
    ClientDataSetFeedsPhed.Clear;
3665
    ClientDataSetFeedsTyrd.Clear;
3666
    ClientDataSetFeedsPheTyrd.Clear;
3667
    ClientDataSetFeedsHisd.Clear;
3668
    ClientDataSetFeedsArgd.Clear;
3669
    ClientDataSetFeedsAlad.Clear;
3670
    ClientDataSetFeedsAspd.Clear;
3671
    ClientDataSetFeedsGlud.Clear;
3672
    ClientDataSetFeedsGlyd.Clear;
3673
    ClientDataSetFeedsSerd.Clear;
3674
    ClientDataSetFeedsProd.Clear;
3675
    // Min?raux
3676
    ClientDataSetFeedsCa.Clear;
3677
    ClientDataSetFeedsP.Clear;
3678
    ClientDataSetFeedsNa.Clear;
3679
    ClientDataSetFeedsK.Clear;
3680
    ClientDataSetFeedsCl.Clear;
3681
    ClientDataSetFeedsBE.Clear;
3682
    ClientDataSetFeedsPd.Clear;
3683
  end
3684
  else
3685
  begin
3686
    // COMPOSITON CHIMIQUE - Initialisation ? z?ro
3687
    // Analyse proximale
3688
    ClientDataSetFeedsMS.Value := 0;
3689
    ClientDataSetFeedsMM.Value := 0;
3690
    ClientDataSetFeedsMAT.Value := 0;
3691
    ClientDataSetFeedsMG.Value := 0;
3692
    ClientDataSetFeedsCB.Value := 0;
3693
    ClientDataSetFeedsNDF.Value := 0;
3694
    ClientDataSetFeedsADF.Value := 0;
3695
    ClientDataSetFeedsADL.Value := 0;
3696
    ClientDataSetFeedsAmidon.Value := 0;
3697
    ClientDataSetFeedsSucres.Value := 0;
3698
    // Energie
3699
    ClientDataSetFeedsEB.Value := 0;
3700
    ClientDataSetFeedsEDc.Value := 0;
3701
    ClientDataSetFeedsEMc.Value := 0;
3702
    ClientDataSetFeedsENc.Value := 0;
3703
    ClientDataSetFeedsEDt.Value := 0;
3704
    ClientDataSetFeedsEMt.Value := 0;
3705
    ClientDataSetFeedsENt.Value := 0;
3706
    // Digestibilit? f?cale de l'azote
3707
    ClientDataSetFeedsdNc.Value := 0;
3708
    ClientDataSetFeedsdNt.Value := 0;
3709
    // Acides amin?s
3710
    ClientDataSetFeedsLys.Value := 0;
3711
    ClientDataSetFeedsThr.Value := 0;
3712
    ClientDataSetFeedsMet.Value := 0;
3713
    ClientDataSetFeedsCys.Value := 0;
3714
    ClientDataSetFeedsMetCys.Value := 0;
3715
    ClientDataSetFeedsTrp.Value := 0;
3716
    ClientDataSetFeedsIle.Value := 0;
3717
    ClientDataSetFeedsVal.Value := 0;
3718
    ClientDataSetFeedsLeu.Value := 0;
3719
    ClientDataSetFeedsPhe.Value := 0;
3720
    ClientDataSetFeedsTyr.Value := 0;
3721
    ClientDataSetFeedsPheTyr.Value := 0;
3722
    ClientDataSetFeedsHis.Value := 0;
3723
    ClientDataSetFeedsArg.Value := 0;
3724
    ClientDataSetFeedsAla.Value := 0;
3725
    ClientDataSetFeedsAsp.Value := 0;
3726
    ClientDataSetFeedsGlu.Value := 0;
3727
    ClientDataSetFeedsGly.Value := 0;
3728
    ClientDataSetFeedsSer.Value := 0;
3729
    ClientDataSetFeedsPro.Value := 0;
3730
    ClientDataSetFeedsLysd.Value := 0;
3731
    ClientDataSetFeedsThrd.Value := 0;
3732
    ClientDataSetFeedsMetd.Value := 0;
3733
    ClientDataSetFeedsCysd.Value := 0;
3734
    ClientDataSetFeedsMetCysd.Value := 0;
3735
    ClientDataSetFeedsTrpd.Value := 0;
3736
    ClientDataSetFeedsIled.Value := 0;
3737
    ClientDataSetFeedsVald.Value := 0;
3738
    ClientDataSetFeedsLeud.Value := 0;
3739
    ClientDataSetFeedsPhed.Value := 0;
3740
    ClientDataSetFeedsTyrd.Value := 0;
3741
    ClientDataSetFeedsPheTyrd.Value := 0;
3742
    ClientDataSetFeedsHisd.Value := 0;
3743
    ClientDataSetFeedsArgd.Value := 0;
3744
    ClientDataSetFeedsAlad.Value := 0;
3745
    ClientDataSetFeedsAspd.Value := 0;
3746
    ClientDataSetFeedsGlud.Value := 0;
3747
    ClientDataSetFeedsGlyd.Value := 0;
3748
    ClientDataSetFeedsSerd.Value := 0;
3749
    ClientDataSetFeedsProd.Value := 0;
3750
    // Min?raux
3751
    ClientDataSetFeedsCa.Value := 0;
3752
    ClientDataSetFeedsP.Value := 0;
3753
    ClientDataSetFeedsNa.Value := 0;
3754
    ClientDataSetFeedsK.Value := 0;
3755
    ClientDataSetFeedsCl.Value := 0;
3756
    ClientDataSetFeedsPd.Value := 0;
3757
    PdEndo := 0;
3758
    ClientDataSetComposition.First;
3759
    while not ClientDataSetComposition.Eof do
3760
    begin
3761
      if ClientDataSetCompositionUser.Value
3762
      then
3763
        ClientDataSetIngredients.Filter := Format('Id = %d and User', [ClientDataSetCompositionIngredient.Value])
3764
      else
3765
        ClientDataSetIngredients.Filter := Format('Id = %d and not User', [ClientDataSetCompositionIngredient.Value]);
3766
      ClientDataSetIngredients.Filtered := True;
3767
      // COMPOSITON CHIMIQUE - Incr?mentation
3768
      Ratio := InputIncorporation(ClientDataSetCompositionLevel.Value, FormOptions.Incorporation);
3769
      ClientDataSetFeedsMS.Value := ClientDataSetFeedsMS.Value + ClientDataSetCompositionMS.Value * Ratio;
3770
      if FormOptions.Expression = 0
3771
      then // Conversion frais -> sec (mati?re s?che de la mati?re premi?re)
3772
        Ratio := Ratio / InputProximal(ClientDataSetIngredientsMS.Value, 1, 1, FormOptions.Proximal);
3773
      RapMS := InputProximal(ClientDataSetCompositionMS.Value, 1, 1, FormOptions.Proximal);
3774
      // Conversion sec -> frais (mati?re s?che de la composition)
3775
      Ratio := Ratio * RapMS;
3776
      // Analyse proximale
3777
      ClientDataSetFeedsMM.Value := ClientDataSetFeedsMM.Value + ClientDataSetIngredientsMM.Value * Ratio;
3778
      ClientDataSetFeedsMAT.Value := ClientDataSetFeedsMAT.Value + ClientDataSetIngredientsMAT.Value * Ratio;
3779
      if not ClientDataSetFeedsMG.IsNull
3780
      then
3781
        if ClientDataSetIngredientsMG.IsNull
3782
        then
3783
          ClientDataSetFeedsMG.Clear
3784
        else
3785
          ClientDataSetFeedsMG.Value := ClientDataSetFeedsMG.Value + ClientDataSetIngredientsMG.Value * Ratio;
3786
      if not ClientDataSetFeedsCB.IsNull
3787
      then
3788
        if ClientDataSetIngredientsCB.IsNull
3789
        then
3790
          ClientDataSetFeedsCB.Clear
3791
        else
3792
          ClientDataSetFeedsCB.Value := ClientDataSetFeedsCB.Value + ClientDataSetIngredientsCB.Value * Ratio;
3793
      if not ClientDataSetFeedsNDF.IsNull
3794
      then
3795
        if ClientDataSetIngredientsNDF.IsNull
3796
        then
3797
          ClientDataSetFeedsNDF.Clear
3798
        else
3799
          ClientDataSetFeedsNDF.Value := ClientDataSetFeedsNDF.Value + ClientDataSetIngredientsNDF.Value * Ratio;
3800
      if not ClientDataSetFeedsADF.IsNull
3801
      then
3802
        if ClientDataSetIngredientsADF.IsNull
3803
        then
3804
          ClientDataSetFeedsADF.Clear
3805
        else
3806
          ClientDataSetFeedsADF.Value := ClientDataSetFeedsADF.Value + ClientDataSetIngredientsADF.Value * Ratio;
3807
      if not ClientDataSetFeedsADL.IsNull
3808
      then
3809
        if ClientDataSetIngredientsADL.IsNull
3810
        then
3811
          ClientDataSetFeedsADL.Clear
3812
        else
3813
          ClientDataSetFeedsADL.Value := ClientDataSetFeedsADL.Value + ClientDataSetIngredientsADL.Value * Ratio;
3814
      if not ClientDataSetFeedsAmidon.IsNull
3815
      then
3816
        if ClientDataSetIngredientsAmidon.IsNull
3817
        then
3818
          ClientDataSetFeedsAmidon.Clear
3819
        else
3820
          ClientDataSetFeedsAmidon.Value := ClientDataSetFeedsAmidon.Value + ClientDataSetIngredientsAmidon.Value * Ratio;
3821
      if not ClientDataSetFeedsSucres.IsNull
3822
      then
3823
        if ClientDataSetIngredientsSucres.IsNull
3824
        then
3825
          ClientDataSetFeedsSucres.Clear
3826
        else
3827
          ClientDataSetFeedsSucres.Value := ClientDataSetFeedsSucres.Value + ClientDataSetIngredientsSucres.Value * Ratio;
3828
      // Energie
3829
      if not ClientDataSetFeedsEB.IsNull
3830
      then
3831
        if ClientDataSetIngredientsEB.IsNull
3832
        then
3833
          ClientDataSetFeedsEB.Clear
3834
        else
3835
          ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value + ClientDataSetIngredientsEB.Value * Ratio;
3836
      if not ClientDataSetFeedsEDc.IsNull
3837
      then
3838
        if ClientDataSetIngredientsEDc.IsNull
3839
        then
3840
          ClientDataSetFeedsEDc.Clear
3841
        else
3842
          ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEDc.Value + ClientDataSetIngredientsEDc.Value * Ratio;
3843
      if not ClientDataSetFeedsEMc.IsNull
3844
      then
3845
        if ClientDataSetIngredientsEMc.IsNull
3846
        then
3847
          ClientDataSetFeedsEMc.Clear
3848
        else
3849
          ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEMc.Value + ClientDataSetIngredientsEMc.Value * Ratio;
3850
      if not ClientDataSetFeedsENc.IsNull
3851
      then
3852
        if ClientDataSetIngredientsENc.IsNull
3853
        then
3854
          ClientDataSetFeedsENc.Clear
3855
        else
3856
          ClientDataSetFeedsENc.Value := ClientDataSetFeedsENc.Value + ClientDataSetIngredientsENc.Value * Ratio;
3857
      if not ClientDataSetFeedsEDt.IsNull
3858
      then
3859
        if ClientDataSetIngredientsEDt.IsNull
3860
        then
3861
          ClientDataSetFeedsEDt.Clear
3862
        else
3863
          ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEDt.Value + ClientDataSetIngredientsEDt.Value * Ratio;
3864
      if not ClientDataSetFeedsEMt.IsNull
3865
      then
3866
        if ClientDataSetIngredientsEMt.IsNull
3867
        then
3868
          ClientDataSetFeedsEMt.Clear
3869
        else
3870
          ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEMt.Value + ClientDataSetIngredientsEMt.Value * Ratio;
3871
      if not ClientDataSetFeedsENt.IsNull
3872
      then
3873
        if ClientDataSetIngredientsENt.IsNull
3874
        then
3875
          ClientDataSetFeedsENt.Clear
3876
        else
3877
          ClientDataSetFeedsENt.Value := ClientDataSetFeedsENt.Value + ClientDataSetIngredientsENt.Value * Ratio;
3878
      // Digestibilit? f?cale de l'azote
3879
      if not ClientDataSetFeedsdNc.IsNull
3880
      then
3881
        if ClientDataSetIngredientsdNc.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3882
        then // Ne devrait pas se produire
3883
          ClientDataSetFeedsdNc.Clear
3884
        else // MATd = MAT * dN
3885
          ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value + ClientDataSetIngredientsMAT.Value * ClientDataSetIngredientsdNc.Value / 100 * Ratio;
3886
      if not ClientDataSetFeedsdNt.IsNull
3887
      then
3888
        if ClientDataSetIngredientsdNt.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3889
        then // Ne devrait pas se produire
3890
          ClientDataSetFeedsdNt.Clear
3891
        else // MATd = MAT * dN
3892
          ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value + ClientDataSetIngredientsMAT.Value * ClientDataSetIngredientsdNt.Value / 100 * Ratio;
3893
      // Acides amin?s
3894
      if not ClientDataSetFeedsLys.IsNull
3895
      then
3896
        if ClientDataSetIngredientsLys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3897
        then
3898
        begin
3899
          ClientDataSetFeedsLys.Clear;
3900
          ClientDataSetFeedsLysd.Clear;
3901
        end
3902
        else
3903
        begin
3904
          ClientDataSetFeedsLys.Value := ClientDataSetFeedsLys.Value + ClientDataSetIngredientsLys.Value * Ratio;
3905
          ClientDataSetFeedsLysd.Value := ClientDataSetFeedsLysd.Value + ClientDataSetIngredientsLysd.Value * Ratio;
3906
        end;
3907
      if not ClientDataSetFeedsThr.IsNull
3908
      then
3909
        if ClientDataSetIngredientsThr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3910
        then
3911
        begin
3912
          ClientDataSetFeedsThr.Clear;
3913
          ClientDataSetFeedsThrd.Clear;
3914
        end
3915
        else
3916
        begin
3917
          ClientDataSetFeedsThr.Value := ClientDataSetFeedsThr.Value + ClientDataSetIngredientsThr.Value * Ratio;
3918
          ClientDataSetFeedsThrd.Value := ClientDataSetFeedsThrd.Value + ClientDataSetIngredientsThrd.Value * Ratio;
3919
        end;
3920
      if not ClientDataSetFeedsMet.IsNull
3921
      then
3922
        if ClientDataSetIngredientsMet.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3923
        then
3924
        begin
3925
          ClientDataSetFeedsMet.Clear;
3926
          ClientDataSetFeedsMetd.Clear;
3927
        end
3928
        else
3929
        begin
3930
          ClientDataSetFeedsMet.Value := ClientDataSetFeedsMet.Value + ClientDataSetIngredientsMet.Value * Ratio;
3931
          ClientDataSetFeedsMetd.Value := ClientDataSetFeedsMetd.Value + ClientDataSetIngredientsMetd.Value * Ratio;
3932
        end;
3933
      if not ClientDataSetFeedsCys.IsNull
3934
      then
3935
        if ClientDataSetIngredientsCys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3936
        then
3937
        begin
3938
          ClientDataSetFeedsCys.Clear;
3939
          ClientDataSetFeedsCysd.Clear;
3940
        end
3941
        else
3942
        begin
3943
          ClientDataSetFeedsCys.Value := ClientDataSetFeedsCys.Value + ClientDataSetIngredientsCys.Value * Ratio;
3944
          ClientDataSetFeedsCysd.Value := ClientDataSetFeedsCysd.Value + ClientDataSetIngredientsCysd.Value * Ratio;
3945
        end;
3946
      if not ClientDataSetFeedsMetCys.IsNull
3947
      then
3948
        if ClientDataSetIngredientsMetCys.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3949
        then
3950
        begin
3951
          ClientDataSetFeedsMetCys.Clear;
3952
          ClientDataSetFeedsMetCysd.Clear;
3953
        end
3954
        else
3955
        begin
3956
          ClientDataSetFeedsMetCys.Value := ClientDataSetFeedsMetCys.Value + ClientDataSetIngredientsMetCys.Value * Ratio;
3957
          ClientDataSetFeedsMetCysd.Value := ClientDataSetFeedsMetCysd.Value + ClientDataSetIngredientsMetCysd.Value * Ratio;
3958
        end;
3959
      if not ClientDataSetFeedsTrp.IsNull
3960
      then
3961
        if ClientDataSetIngredientsTrp.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3962
        then
3963
        begin
3964
          ClientDataSetFeedsTrp.Clear;
3965
          ClientDataSetFeedsTrpd.Clear;
3966
        end
3967
        else
3968
        begin
3969
          ClientDataSetFeedsTrp.Value := ClientDataSetFeedsTrp.Value + ClientDataSetIngredientsTrp.Value * Ratio;
3970
          ClientDataSetFeedsTrpd.Value := ClientDataSetFeedsTrpd.Value + ClientDataSetIngredientsTrpd.Value * Ratio;
3971
        end;
3972
      if not ClientDataSetFeedsIle.IsNull
3973
      then
3974
        if ClientDataSetIngredientsIle.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3975
        then
3976
        begin
3977
          ClientDataSetFeedsIle.Clear;
3978
          ClientDataSetFeedsIled.Clear;
3979
        end
3980
        else
3981
        begin
3982
          ClientDataSetFeedsIle.Value := ClientDataSetFeedsIle.Value + ClientDataSetIngredientsIle.Value * Ratio;
3983
          ClientDataSetFeedsIled.Value := ClientDataSetFeedsIled.Value + ClientDataSetIngredientsIled.Value * Ratio;
3984
        end;
3985
      if not ClientDataSetFeedsVal.IsNull
3986
      then
3987
        if ClientDataSetIngredientsVal.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
3988
        then
3989
        begin
3990
          ClientDataSetFeedsVal.Clear;
3991
          ClientDataSetFeedsVald.Clear;
3992
        end
3993
        else
3994
        begin
3995
          ClientDataSetFeedsVal.Value := ClientDataSetFeedsVal.Value + ClientDataSetIngredientsVal.Value * Ratio;
3996
          ClientDataSetFeedsVald.Value := ClientDataSetFeedsVald.Value + ClientDataSetIngredientsVald.Value * Ratio;
3997
        end;
3998
      if not ClientDataSetFeedsLeu.IsNull
3999
      then
4000
        if ClientDataSetIngredientsLeu.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4001
        then
4002
        begin
4003
          ClientDataSetFeedsLeu.Clear;
4004
          ClientDataSetFeedsLeud.Clear;
4005
        end
4006
        else
4007
        begin
4008
          ClientDataSetFeedsLeu.Value := ClientDataSetFeedsLeu.Value + ClientDataSetIngredientsLeu.Value * Ratio;
4009
          ClientDataSetFeedsLeud.Value := ClientDataSetFeedsLeud.Value + ClientDataSetIngredientsLeud.Value * Ratio;
4010
        end;
4011
      if not ClientDataSetFeedsPhe.IsNull
4012
      then
4013
        if ClientDataSetIngredientsPhe.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4014
        then
4015
        begin
4016
          ClientDataSetFeedsPhe.Clear;
4017
          ClientDataSetFeedsPhed.Clear;
4018
        end
4019
        else
4020
        begin
4021
          ClientDataSetFeedsPhe.Value := ClientDataSetFeedsPhe.Value + ClientDataSetIngredientsPhe.Value * Ratio;
4022
          ClientDataSetFeedsPhed.Value := ClientDataSetFeedsPhed.Value + ClientDataSetIngredientsPhed.Value * Ratio;
4023
        end;
4024
      if not ClientDataSetFeedsTyr.IsNull
4025
      then
4026
        if ClientDataSetIngredientsTyr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4027
        then
4028
        begin
4029
          ClientDataSetFeedsTyr.Clear;
4030
          ClientDataSetFeedsTyrd.Clear;
4031
        end
4032
        else
4033
        begin
4034
          ClientDataSetFeedsTyr.Value := ClientDataSetFeedsTyr.Value + ClientDataSetIngredientsTyr.Value * Ratio;
4035
          ClientDataSetFeedsTyrd.Value := ClientDataSetFeedsTyrd.Value + ClientDataSetIngredientsTyrd.Value * Ratio;
4036
        end;
4037
      if not ClientDataSetFeedsPheTyr.IsNull
4038
      then
4039
        if ClientDataSetIngredientsPheTyr.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4040
        then
4041
        begin
4042
          ClientDataSetFeedsPheTyr.Clear;
4043
          ClientDataSetFeedsPheTyrd.Clear;
4044
        end
4045
        else
4046
        begin
4047
          ClientDataSetFeedsPheTyr.Value := ClientDataSetFeedsPheTyr.Value + ClientDataSetIngredientsPheTyr.Value * Ratio;
4048
          ClientDataSetFeedsPheTyrd.Value := ClientDataSetFeedsPheTyrd.Value + ClientDataSetIngredientsPheTyrd.Value * Ratio;
4049
        end;
4050
      if not ClientDataSetFeedsHis.IsNull
4051
      then
4052
        if ClientDataSetIngredientsHis.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4053
        then
4054
        begin
4055
          ClientDataSetFeedsHis.Clear;
4056
          ClientDataSetFeedsHisd.Clear;
4057
        end
4058
        else
4059
        begin
4060
          ClientDataSetFeedsHis.Value := ClientDataSetFeedsHis.Value + ClientDataSetIngredientsHis.Value * Ratio;
4061
          ClientDataSetFeedsHisd.Value := ClientDataSetFeedsHisd.Value + ClientDataSetIngredientsHisd.Value * Ratio;
4062
        end;
4063
      if not ClientDataSetFeedsArg.IsNull
4064
      then
4065
        if ClientDataSetIngredientsArg.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4066
        then
4067
        begin
4068
          ClientDataSetFeedsArg.Clear;
4069
          ClientDataSetFeedsArgd.Clear;
4070
        end
4071
        else
4072
        begin
4073
          ClientDataSetFeedsArg.Value := ClientDataSetFeedsArg.Value + ClientDataSetIngredientsArg.Value * Ratio;
4074
          ClientDataSetFeedsArgd.Value := ClientDataSetFeedsArgd.Value + ClientDataSetIngredientsArgd.Value * Ratio;
4075
        end;
4076
      if not ClientDataSetFeedsAla.IsNull
4077
      then
4078
        if ClientDataSetIngredientsAla.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4079
        then
4080
        begin
4081
          ClientDataSetFeedsAla.Clear;
4082
          ClientDataSetFeedsAlad.Clear;
4083
        end
4084
        else
4085
        begin
4086
          ClientDataSetFeedsAla.Value := ClientDataSetFeedsAla.Value + ClientDataSetIngredientsAla.Value * Ratio;
4087
          ClientDataSetFeedsAlad.Value := ClientDataSetFeedsAlad.Value + ClientDataSetIngredientsAlad.Value * Ratio;
4088
        end;
4089
      if not ClientDataSetFeedsAsp.IsNull
4090
      then
4091
        if ClientDataSetIngredientsAsp.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4092
        then
4093
        begin
4094
          ClientDataSetFeedsAsp.Clear;
4095
          ClientDataSetFeedsAspd.Clear;
4096
        end
4097
        else
4098
        begin
4099
          ClientDataSetFeedsAsp.Value := ClientDataSetFeedsAsp.Value + ClientDataSetIngredientsAsp.Value * Ratio;
4100
          ClientDataSetFeedsAspd.Value := ClientDataSetFeedsAspd.Value + ClientDataSetIngredientsAspd.Value * Ratio;
4101
        end;
4102
      if not ClientDataSetFeedsGlu.IsNull
4103
      then
4104
        if ClientDataSetIngredientsGlu.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4105
        then
4106
        begin
4107
          ClientDataSetFeedsGlu.Clear;
4108
          ClientDataSetFeedsGlud.Clear;
4109
        end
4110
        else
4111
        begin
4112
          ClientDataSetFeedsGlu.Value := ClientDataSetFeedsGlu.Value + ClientDataSetIngredientsGlu.Value * Ratio;
4113
          ClientDataSetFeedsGlud.Value := ClientDataSetFeedsGlud.Value + ClientDataSetIngredientsGlud.Value * Ratio;
4114
        end;
4115
      if not ClientDataSetFeedsGly.IsNull
4116
      then
4117
        if ClientDataSetIngredientsGly.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4118
        then
4119
        begin
4120
          ClientDataSetFeedsGly.Clear;
4121
          ClientDataSetFeedsGlyd.Clear;
4122
        end
4123
        else
4124
        begin
4125
          ClientDataSetFeedsGly.Value := ClientDataSetFeedsGly.Value + ClientDataSetIngredientsGly.Value * Ratio;
4126
          ClientDataSetFeedsGlyd.Value := ClientDataSetFeedsGlyd.Value + ClientDataSetIngredientsGlyd.Value * Ratio;
4127
        end;
4128
      if not ClientDataSetFeedsSer.IsNull
4129
      then
4130
        if ClientDataSetIngredientsSer.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4131
        then
4132
        begin
4133
          ClientDataSetFeedsSer.Clear;
4134
          ClientDataSetFeedsSerd.Clear;
4135
        end
4136
        else
4137
        begin
4138
          ClientDataSetFeedsSer.Value := ClientDataSetFeedsSer.Value + ClientDataSetIngredientsSer.Value * Ratio;
4139
          ClientDataSetFeedsSerd.Value := ClientDataSetFeedsSerd.Value + ClientDataSetIngredientsSerd.Value * Ratio;
4140
        end;
4141
      if not ClientDataSetFeedsPro.IsNull
4142
      then
4143
        if ClientDataSetIngredientsPro.IsNull and (ClientDataSetIngredientsMAT.Value <> 0)
4144
        then
4145
        begin
4146
          ClientDataSetFeedsPro.Clear;
4147
          ClientDataSetFeedsProd.Clear;
4148
        end
4149
        else
4150
        begin
4151
          ClientDataSetFeedsPro.Value := ClientDataSetFeedsPro.Value + ClientDataSetIngredientsPro.Value * Ratio;
4152
          ClientDataSetFeedsProd.Value := ClientDataSetFeedsProd.Value + ClientDataSetIngredientsProd.Value * Ratio;
4153
        end;
4154
      // Min?raux
4155
      if not ClientDataSetFeedsCa.IsNull
4156
      then
4157
        if ClientDataSetIngredientsCa.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4158
        then
4159
          ClientDataSetFeedsCa.Clear
4160
        else
4161
          ClientDataSetFeedsCa.Value := ClientDataSetFeedsCa.Value + ClientDataSetIngredientsCa.Value * Ratio;
4162
      if not ClientDataSetFeedsP.IsNull
4163
      then
4164
        if ClientDataSetIngredientsP.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4165
        then
4166
          ClientDataSetFeedsP.Clear
4167
        else
4168
          ClientDataSetFeedsP.Value := ClientDataSetFeedsP.Value + ClientDataSetIngredientsP.Value * Ratio;
4169
      if not ClientDataSetFeedsNa.IsNull
4170
      then
4171
        if ClientDataSetIngredientsNa.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4172
        then
4173
          ClientDataSetFeedsNa.Clear
4174
        else
4175
          ClientDataSetFeedsNa.Value := ClientDataSetFeedsNa.Value + ClientDataSetIngredientsNa.Value * Ratio;
4176
      if not ClientDataSetFeedsK.IsNull
4177
      then
4178
        if ClientDataSetIngredientsK.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4179
        then
4180
          ClientDataSetFeedsK.Clear
4181
        else
4182
          ClientDataSetFeedsK.Value := ClientDataSetFeedsK.Value + ClientDataSetIngredientsK.Value * Ratio;
4183
      if not ClientDataSetFeedsCl.IsNull
4184
      then
4185
        if ClientDataSetIngredientsCl.IsNull and (ClientDataSetIngredientsMM.Value <> 0)
4186
        then
4187
          ClientDataSetFeedsCl.Clear
4188
        else
4189
          ClientDataSetFeedsCl.Value := ClientDataSetFeedsCl.Value + ClientDataSetIngredientsCl.Value * Ratio;
4190
      if ClientDataSetFeedsNa.IsNull or ClientDataSetFeedsK.IsNull or ClientDataSetFeedsCl.IsNull
4191
      then
4192
        ClientDataSetFeedsBE.Clear
4193
      else
4194
        ClientDataSetFeedsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetFeedsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
4195
      if not ClientDataSetFeedsPd.IsNull
4196
      then
4197
        if ClientDataSetFeedsPresentation.Value = 0
4198
        then // Farine (dPphy)
4199
          if ClientDataSetIngredientsdPphy.IsNull and (ClientDataSetIngredientsP.Value <> 0) and (ClientDataSetIngredientsMM.Value <> 0)
4200
          then
4201
            ClientDataSetFeedsPd.Clear
4202
          else
4203
            ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + (ClientDataSetIngredientsdPphy.Value / 100 * ClientDataSetIngredientsP.Value) * Ratio
4204
        else // Granul?s (dP)
4205
          if ClientDataSetIngredientsdP.IsNull and (ClientDataSetIngredientsP.Value <> 0) and (ClientDataSetIngredientsMM.Value <> 0)
4206
          then
4207
            ClientDataSetFeedsPd.Clear
4208
          else
4209
            ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + (ClientDataSetIngredientsdP.Value / 100 * ClientDataSetIngredientsP.Value) * Ratio;
4210
      PdEndo := PdEndo + ((ClientDataSetIngredientsdPphy.Value - ClientDataSetIngredientsdP.Value) / 100 * ClientDataSetIngredientsP.Value) * Ratio;
4211
      ClientDataSetIngredients.Filtered := False;
4212
      ClientDataSetIngredients.Filter := '';
4213
      ClientDataSetComposition.Next;
4214
    end;
4215
    // Phytase
4216
    if not TableFeeds.FieldIsNull(TableFeeds.FieldIndex['Phytase'])
4217
    and not ClientDataSetFeedsPd.IsNull
4218
    then // Phosphore digestible lib?r? par la phytase
4219
    begin
4220
      PhytaseMicro := ClientDataSetFeedsPhytaseIncorporation.Value;
4221
      ClientDataSetPhytase.Locate('Id', ClientDataSetFeedsPhytaseId.Value, []);
4222
      CoefPhytase := ClientDataSetPhytaseCoef.Value;
4223
      if ClientDataSetFeedsPresentation.Value = 0
4224
      then // Farine (dPphy)
4225
      begin
4226
        if FormOptions.Minerals = 0
4227
        then // Conversion % -> g/kg
4228
          PdEndo := PdEndo / 100 * 1000;
4229
        PdEndo := Min(PdEndo, 0.4); // Limiter ? 0.4 g/kg
4230
        PhytaseEndo := -Ln(1 - PdEndo / a) / (b * CoefPhytase);
4231
        PdMicro := a * (1 - Exp(-b * (PhytaseMicro + PhytaseEndo) * CoefPhytase))
4232
          - a * (1 - Exp(-b * PhytaseEndo * CoefPhytase));
4233
      end
4234
      else // Granul?s (dP)
4235
        PdMicro := a * (1 - Exp(-b * PhytaseMicro * CoefPhytase));
4236
      if FormOptions.Minerals = 0
4237
      then // Conversion g/kg -> %
4238
        PdMicro := PdMicro / 1000 * 100;
4239
      ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value + PdMicro;
4240
    end;
4241
    RapMS := InputProximal(ClientDataSetFeedsMS.Value, 1, 1, FormOptions.Proximal);
4242
    ClientDataSetFeedsMS2.Value := OutputProximal(1, RapMS, FormOptions.Expression, FormOptions.Proximal);
4243
    if FormOptions.Expression = 1
4244
    then // Conversion frais -> sec (mati?re s?che du r?gime)
4245
    begin
4246
      // Analyse proximale
4247
      ClientDataSetFeedsMM.Value := ClientDataSetFeedsMM.Value / RapMS;
4248
      ClientDataSetFeedsMAT.Value := ClientDataSetFeedsMAT.Value / RapMS;
4249
      if not ClientDataSetFeedsMG.IsNull
4250
      then
4251
        ClientDataSetFeedsMG.Value := ClientDataSetFeedsMG.Value / RapMS;
4252
      if not ClientDataSetFeedsCB.IsNull
4253
      then
4254
        ClientDataSetFeedsCB.Value := ClientDataSetFeedsCB.Value / RapMS;
4255
      if not ClientDataSetFeedsNDF.IsNull
4256
      then
4257
        ClientDataSetFeedsNDF.Value := ClientDataSetFeedsNDF.Value / RapMS;
4258
      if not ClientDataSetFeedsADF.IsNull
4259
      then
4260
        ClientDataSetFeedsADF.Value := ClientDataSetFeedsADF.Value / RapMS;
4261
      if not ClientDataSetFeedsADL.IsNull
4262
      then
4263
        ClientDataSetFeedsADL.Value := ClientDataSetFeedsADL.Value / RapMS;
4264
      if not ClientDataSetFeedsAmidon.IsNull
4265
      then
4266
        ClientDataSetFeedsAmidon.Value := ClientDataSetFeedsAmidon.Value / RapMS;
4267
      if not ClientDataSetFeedsSucres.IsNull
4268
      then
4269
        ClientDataSetFeedsSucres.Value := ClientDataSetFeedsSucres.Value / RapMS;
4270
      // Energie
4271
      if not ClientDataSetFeedsEB.IsNull
4272
      then
4273
        ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value / RapMS;
4274
      if not ClientDataSetFeedsEDc.IsNull
4275
      then
4276
        ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEDc.Value / RapMS;
4277
      if not ClientDataSetFeedsEMc.IsNull
4278
      then
4279
        ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEMc.Value / RapMS;
4280
      if not ClientDataSetFeedsENc.IsNull
4281
      then
4282
        ClientDataSetFeedsENc.Value := ClientDataSetFeedsENc.Value / RapMS;
4283
      if not ClientDataSetFeedsEDt.IsNull
4284
      then
4285
        ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEDt.Value / RapMS;
4286
      if not ClientDataSetFeedsEMt.IsNull
4287
      then
4288
        ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEMt.Value / RapMS;
4289
      if not ClientDataSetFeedsENt.IsNull
4290
      then
4291
        ClientDataSetFeedsENt.Value := ClientDataSetFeedsENt.Value / RapMS;
4292
      // Digestibilit? f?cale de l'azote
4293
      if not ClientDataSetFeedsdNc.IsNull
4294
      then
4295
        ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value / RapMS;
4296
      if not ClientDataSetFeedsdNt.IsNull
4297
      then
4298
        ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value / RapMS;
4299
      // Acides amin?s
4300
      if not ClientDataSetFeedsLys.IsNull
4301
      then
4302
      begin
4303
        ClientDataSetFeedsLys.Value := ClientDataSetFeedsLys.Value / RapMS;
4304
        ClientDataSetFeedsLysd.Value := ClientDataSetFeedsLysd.Value / RapMS;
4305
      end;
4306
      if not ClientDataSetFeedsThr.IsNull
4307
      then
4308
      begin
4309
        ClientDataSetFeedsThr.Value := ClientDataSetFeedsThr.Value / RapMS;
4310
        ClientDataSetFeedsThrd.Value := ClientDataSetFeedsThrd.Value / RapMS;
4311
      end;
4312
      if not ClientDataSetFeedsMet.IsNull
4313
      then
4314
      begin
4315
        ClientDataSetFeedsMet.Value := ClientDataSetFeedsMet.Value / RapMS;
4316
        ClientDataSetFeedsMetd.Value := ClientDataSetFeedsMetd.Value / RapMS;
4317
      end;
4318
      if not ClientDataSetFeedsCys.IsNull
4319
      then
4320
      begin
4321
        ClientDataSetFeedsCys.Value := ClientDataSetFeedsCys.Value / RapMS;
4322
        ClientDataSetFeedsCysd.Value := ClientDataSetFeedsCysd.Value / RapMS;
4323
      end;
4324
      if not ClientDataSetFeedsMetCys.IsNull
4325
      then
4326
      begin
4327
        ClientDataSetFeedsMetCys.Value := ClientDataSetFeedsMetCys.Value / RapMS;
4328
        ClientDataSetFeedsMetCysd.Value := ClientDataSetFeedsMetCysd.Value / RapMS;
4329
      end;
4330
      if not ClientDataSetFeedsTrp.IsNull
4331
      then
4332
      begin
4333
        ClientDataSetFeedsTrp.Value := ClientDataSetFeedsTrp.Value / RapMS;
4334
        ClientDataSetFeedsTrpd.Value := ClientDataSetFeedsTrpd.Value / RapMS;
4335
      end;
4336
      if not ClientDataSetFeedsIle.IsNull
4337
      then
4338
      begin
4339
        ClientDataSetFeedsIle.Value := ClientDataSetFeedsIle.Value / RapMS;
4340
        ClientDataSetFeedsIled.Value := ClientDataSetFeedsIled.Value / RapMS;
4341
      end;
4342
      if not ClientDataSetFeedsVal.IsNull
4343
      then
4344
      begin
4345
        ClientDataSetFeedsVal.Value := ClientDataSetFeedsVal.Value / RapMS;
4346
        ClientDataSetFeedsVald.Value := ClientDataSetFeedsVald.Value / RapMS;
4347
      end;
4348
      if not ClientDataSetFeedsLeu.IsNull
4349
      then
4350
      begin
4351
        ClientDataSetFeedsLeu.Value := ClientDataSetFeedsLeu.Value / RapMS;
4352
        ClientDataSetFeedsLeud.Value := ClientDataSetFeedsLeud.Value / RapMS;
4353
      end;
4354
      if not ClientDataSetFeedsPhe.IsNull
4355
      then
4356
      begin
4357
        ClientDataSetFeedsPhe.Value := ClientDataSetFeedsPhe.Value / RapMS;
4358
        ClientDataSetFeedsPhed.Value := ClientDataSetFeedsPhed.Value / RapMS;
4359
      end;
4360
      if not ClientDataSetFeedsTyr.IsNull
4361
      then
4362
      begin
4363
        ClientDataSetFeedsTyr.Value := ClientDataSetFeedsTyr.Value / RapMS;
4364
        ClientDataSetFeedsTyrd.Value := ClientDataSetFeedsTyrd.Value / RapMS;
4365
      end;
4366
      if not ClientDataSetFeedsPheTyr.IsNull
4367
      then
4368
      begin
4369
        ClientDataSetFeedsPheTyr.Value := ClientDataSetFeedsPheTyr.Value / RapMS;
4370
        ClientDataSetFeedsPheTyrd.Value := ClientDataSetFeedsPheTyrd.Value / RapMS;
4371
      end;
4372
      if not ClientDataSetFeedsHis.IsNull
4373
      then
4374
      begin
4375
        ClientDataSetFeedsHis.Value := ClientDataSetFeedsHis.Value / RapMS;
4376
        ClientDataSetFeedsHisd.Value := ClientDataSetFeedsHisd.Value / RapMS;
4377
      end;
4378
      if not ClientDataSetFeedsArg.IsNull
4379
      then
4380
      begin
4381
        ClientDataSetFeedsArg.Value := ClientDataSetFeedsArg.Value / RapMS;
4382
        ClientDataSetFeedsArgd.Value := ClientDataSetFeedsArgd.Value / RapMS;
4383
      end;
4384
      if not ClientDataSetFeedsAla.IsNull
4385
      then
4386
      begin
4387
        ClientDataSetFeedsAla.Value := ClientDataSetFeedsAla.Value / RapMS;
4388
        ClientDataSetFeedsAlad.Value := ClientDataSetFeedsAlad.Value / RapMS;
4389
      end;
4390
      if not ClientDataSetFeedsAsp.IsNull
4391
      then
4392
      begin
4393
        ClientDataSetFeedsAsp.Value := ClientDataSetFeedsAsp.Value / RapMS;
4394
        ClientDataSetFeedsAspd.Value := ClientDataSetFeedsAspd.Value / RapMS;
4395
      end;
4396
      if not ClientDataSetFeedsGlu.IsNull
4397
      then
4398
      begin
4399
        ClientDataSetFeedsGlu.Value := ClientDataSetFeedsGlu.Value / RapMS;
4400
        ClientDataSetFeedsGlud.Value := ClientDataSetFeedsGlud.Value / RapMS;
4401
      end;
4402
      if not ClientDataSetFeedsGly.IsNull
4403
      then
4404
      begin
4405
        ClientDataSetFeedsGly.Value := ClientDataSetFeedsGly.Value / RapMS;
4406
        ClientDataSetFeedsGlyd.Value := ClientDataSetFeedsGlyd.Value / RapMS;
4407
      end;
4408
      if not ClientDataSetFeedsSer.IsNull
4409
      then
4410
      begin
4411
        ClientDataSetFeedsSer.Value := ClientDataSetFeedsSer.Value / RapMS;
4412
        ClientDataSetFeedsSerd.Value := ClientDataSetFeedsSerd.Value / RapMS;
4413
      end;
4414
      if not ClientDataSetFeedsPro.IsNull
4415
      then
4416
      begin
4417
        ClientDataSetFeedsPro.Value := ClientDataSetFeedsPro.Value / RapMS;
4418
        ClientDataSetFeedsProd.Value := ClientDataSetFeedsProd.Value / RapMS;
4419
      end;
4420
      // Min?raux
4421
      if not ClientDataSetFeedsCa.IsNull
4422
      then
4423
        ClientDataSetFeedsCa.Value := ClientDataSetFeedsCa.Value / RapMS;
4424
      if not ClientDataSetFeedsP.IsNull
4425
      then
4426
        ClientDataSetFeedsP.Value := ClientDataSetFeedsP.Value / RapMS;
4427
      if not ClientDataSetFeedsNa.IsNull
4428
      then
4429
        ClientDataSetFeedsNa.Value := ClientDataSetFeedsNa.Value / RapMS;
4430
      if not ClientDataSetFeedsK.IsNull
4431
      then
4432
        ClientDataSetFeedsK.Value := ClientDataSetFeedsK.Value / RapMS;
4433
      if not ClientDataSetFeedsCl.IsNull
4434
      then
4435
        ClientDataSetFeedsCl.Value := ClientDataSetFeedsCl.Value / RapMS;
4436
      if not ClientDataSetFeedsEB.IsNull
4437
      then
4438
        ClientDataSetFeedsEB.Value := ClientDataSetFeedsEB.Value / RapMS;
4439
      if not ClientDataSetFeedsPd.IsNull
4440
      then
4441
        ClientDataSetFeedsPd.Value := ClientDataSetFeedsPd.Value / RapMS;
4442
    end;
4443
  end;
4444
  if ClientDataSetFeedsNa.IsNull or ClientDataSetFeedsK.IsNull or ClientDataSetFeedsCl.IsNull
4445
  then
4446
    ClientDataSetFeedsBE.Clear
4447
  else
4448
    ClientDataSetFeedsBE.Value := CalcBilanElectrolytique(InputMinerals(ClientDataSetFeedsNa.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsK.Value, RapMS, FormOptions.Expression, FormOptions.Minerals), InputMinerals(ClientDataSetFeedsCl.Value, RapMS, FormOptions.Expression, FormOptions.Minerals));
4449
  // Rapports
4450
  if ClientDataSetFeedsEDc.IsNull or ClientDataSetFeedsEB.IsNull or (ClientDataSetFeedsEB.Value = 0)
4451
  then
4452
    ClientDataSetFeedsdEc.Clear
4453
  else
4454
    ClientDataSetFeedsdEc.Value := ClientDataSetFeedsEDc.Value / ClientDataSetFeedsEB.Value * 100;
4455
  if ClientDataSetFeedsEMc.IsNull or ClientDataSetFeedsEDc.IsNull or (ClientDataSetFeedsEDc.Value = 0)
4456
  then
4457
    ClientDataSetFeedsEMc_EDc.Clear
4458
  else
4459
    ClientDataSetFeedsEMc_EDc.Value := ClientDataSetFeedsEMc.Value / ClientDataSetFeedsEDc.Value * 100;
4460
  if ClientDataSetFeedsENc.IsNull or ClientDataSetFeedsEMc.IsNull or (ClientDataSetFeedsEMc.Value = 0)
4461
  then
4462
    ClientDataSetFeedsENc_EMc.Clear
4463
  else
4464
    ClientDataSetFeedsENc_EMc.Value := ClientDataSetFeedsENc.Value / ClientDataSetFeedsEMc.Value * 100;
4465
  if ClientDataSetFeedsEDt.IsNull or ClientDataSetFeedsEB.IsNull or (ClientDataSetFeedsEB.Value = 0)
4466
  then
4467
    ClientDataSetFeedsdEt.Clear
4468
  else
4469
    ClientDataSetFeedsdEt.Value := ClientDataSetFeedsEDt.Value / ClientDataSetFeedsEB.Value * 100;
4470
  if ClientDataSetFeedsEMt.IsNull or ClientDataSetFeedsEDt.IsNull or (ClientDataSetFeedsEDt.Value = 0)
4471
  then
4472
    ClientDataSetFeedsEMt_EDt.Clear
4473
  else
4474
    ClientDataSetFeedsEMt_EDt.Value := ClientDataSetFeedsEMt.Value / ClientDataSetFeedsEDt.Value * 100;
4475
  if ClientDataSetFeedsENt.IsNull or ClientDataSetFeedsEMt.IsNull or (ClientDataSetFeedsEMt.Value = 0)
4476
  then
4477
    ClientDataSetFeedsENt_EMt.Clear
4478
  else
4479
    ClientDataSetFeedsENt_EMt.Value := ClientDataSetFeedsENt.Value / ClientDataSetFeedsEMt.Value * 100;
4480
  if ClientDataSetFeedsBonusC.Value <> 0
4481
  then // Prise en compte du bonus (porc croissance)
4482
  begin
4483
    if not ClientDataSetFeedsdEc.IsNull
4484
    then
4485
      ClientDataSetFeedsdEc.Value := ClientDataSetFeedsdEc.Value + ClientDataSetFeedsBonusC.Value;
4486
    if not ClientDataSetFeedsEB.IsNull and not ClientDataSetFeedsdEc.IsNull
4487
    then
4488
      ClientDataSetFeedsEDc.Value := ClientDataSetFeedsEB.Value * ClientDataSetFeedsdEc.Value / 100;
4489
    if not ClientDataSetFeedsEDc.IsNull and not ClientDataSetFeedsEMc_EDc.IsNull
4490
    then
4491
      ClientDataSetFeedsEMc.Value := ClientDataSetFeedsEDc.Value * ClientDataSetFeedsEMc_EDc.Value / 100;
4492
    if not ClientDataSetFeedsEMc.IsNull and not ClientDataSetFeedsENc_EMc.IsNull
4493
    then
4494
      ClientDataSetFeedsENc.Value := ClientDataSetFeedsEMc.Value * ClientDataSetFeedsENc_EMc.Value / 100;
4495
  end;
4496
  if ClientDataSetFeedsBonusT.Value <> 0
4497
  then // Prise en compte du bonus (porce adulte)
4498
  begin
4499
    if not ClientDataSetFeedsdEt.IsNull
4500
    then
4501
      ClientDataSetFeedsdEt.Value := ClientDataSetFeedsdEt.Value + ClientDataSetFeedsBonusT.Value;
4502
    if not ClientDataSetFeedsEB.IsNull and not ClientDataSetFeedsdEt.IsNull
4503
    then
4504
      ClientDataSetFeedsEDt.Value := ClientDataSetFeedsEB.Value * ClientDataSetFeedsdEt.Value / 100;
4505
    if not ClientDataSetFeedsEDt.IsNull and not ClientDataSetFeedsEMt_EDt.IsNull
4506
    then
4507
      ClientDataSetFeedsEMt.Value := ClientDataSetFeedsEDt.Value * ClientDataSetFeedsEMt_EDt.Value / 100;
4508
    if not ClientDataSetFeedsEMt.IsNull and not ClientDataSetFeedsENt_EMt.IsNull
4509
    then
4510
      ClientDataSetFeedsENt.Value := ClientDataSetFeedsEMt.Value * ClientDataSetFeedsENt_EMt.Value / 100;
4511
  end;
4512
  if ClientDataSetFeedsEDt.IsNull or ClientDataSetFeedsEDc.IsNull or (ClientDataSetFeedsEDc.Value = 0)
4513
  then
4514
    ClientDataSetFeedsEDt_EDc.Clear
4515
  else
4516
    ClientDataSetFeedsEDt_EDc.Value := ClientDataSetFeedsEDt.Value / ClientDataSetFeedsEDc.Value * 100;
4517
  if ClientDataSetFeedsEMt.IsNull or ClientDataSetFeedsEMc.IsNull or (ClientDataSetFeedsEMc.Value = 0)
4518
  then
4519
    ClientDataSetFeedsEMt_EMc.Clear
4520
  else
4521
    ClientDataSetFeedsEMt_EMc.Value := ClientDataSetFeedsEMt.Value / ClientDataSetFeedsEMc.Value * 100;
4522
  if ClientDataSetFeedsENt.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4523
  then
4524
    ClientDataSetFeedsENt_ENc.Clear
4525
  else
4526
    ClientDataSetFeedsENt_ENc.Value := ClientDataSetFeedsENt.Value / ClientDataSetFeedsENc.Value * 100;
4527
  if not ClientDataSetFeedsdNc.IsNull
4528
  then
4529
    if ClientDataSetFeedsMAT.IsNull or (ClientDataSetFeedsMAT.Value = 0)
4530
    then
4531
      ClientDataSetFeedsdNc.Clear
4532
    else // dN = MATd / MAT
4533
      ClientDataSetFeedsdNc.Value := ClientDataSetFeedsdNc.Value / ClientDataSetFeedsMAT.Value * 100;
4534
  if not ClientDataSetFeedsdNt.IsNull
4535
  then
4536
    if ClientDataSetFeedsMAT.IsNull or (ClientDataSetFeedsMAT.Value = 0)
4537
    then
4538
      ClientDataSetFeedsdNt.Clear
4539
    else // dN = MATd / MAT
4540
      ClientDataSetFeedsdNt.Value := ClientDataSetFeedsdNt.Value / ClientDataSetFeedsMAT.Value * 100;
4541
  if ClientDataSetFeedsLysd.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4542
  then
4543
    ClientDataSetFeedsLysd_ENc.Clear
4544
  else
4545
    if FormOptions.Energy = 0
4546
    then // g/MJ
4547
      if FormOptions.AA = 0
4548
      then // % (conversion)
4549
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value
4550
      else // g/kg
4551
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENc.Value
4552
    else // g/1000kcal
4553
      if FormOptions.AA = 0
4554
      then // % (conversion)
4555
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value * 1000
4556
      else // g/kg
4557
        ClientDataSetFeedsLysd_ENc.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENc.Value * 1000;
4558
  if ClientDataSetFeedsLysd.IsNull or ClientDataSetFeedsENt.IsNull or (ClientDataSetFeedsENt.Value = 0)
4559
  then
4560
    ClientDataSetFeedsLysd_ENt.Clear
4561
  else
4562
    if FormOptions.Energy = 0
4563
    then // g/MJ
4564
      if FormOptions.AA = 0
4565
      then // % (conversion)
4566
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value
4567
      else // g/kg
4568
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENt.Value
4569
    else // g/1000kcal
4570
      if FormOptions.AA = 0
4571
      then // % (conversion)
4572
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value * 1000
4573
      else // g/kg
4574
        ClientDataSetFeedsLysd_ENt.Value := ClientDataSetFeedsLysd.Value / ClientDataSetFeedsENt.Value * 1000;
4575
  if ClientDataSetFeedsCa.IsNull or ClientDataSetFeedsPd.IsNull or (ClientDataSetFeedsPd.Value = 0)
4576
  then
4577
    ClientDataSetFeedsCa_Pd.Clear
4578
  else
4579
    ClientDataSetFeedsCa_Pd.Value := ClientDataSetFeedsCa.Value / ClientDataSetFeedsPd.Value;
4580
  if ClientDataSetFeedsPd.IsNull or ClientDataSetFeedsENc.IsNull or (ClientDataSetFeedsENc.Value = 0)
4581
  then
4582
    ClientDataSetFeedsPd_ENc.Clear
4583
  else
4584
    if FormOptions.Energy = 0
4585
    then // g/MJ
4586
      if FormOptions.Minerals = 0
4587
      then // % (conversion)
4588
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value
4589
      else // g/kg
4590
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENc.Value
4591
    else // g/1000kcal
4592
      if FormOptions.Minerals = 0
4593
      then // % (conversion)
4594
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENc.Value * 1000
4595
      else // g/kg
4596
        ClientDataSetFeedsPd_ENc.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENc.Value * 1000;
4597
  if ClientDataSetFeedsPd.IsNull or ClientDataSetFeedsENt.IsNull or (ClientDataSetFeedsENt.Value = 0)
4598
  then
4599
    ClientDataSetFeedsPd_ENt.Clear
4600
  else
4601
    if FormOptions.Energy = 0
4602
    then // g/MJ
4603
      if FormOptions.Minerals = 0
4604
      then // % (conversion)
4605
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value
4606
      else // g/kg
4607
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENt.Value
4608
    else // g/1000 kcal
4609
      if FormOptions.Minerals = 0
4610
      then // % (conversion)
4611
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / 100 * 1000 / ClientDataSetFeedsENt.Value * 1000
4612
      else // g/kg
4613
        ClientDataSetFeedsPd_ENt.Value := ClientDataSetFeedsPd.Value / ClientDataSetFeedsENt.Value * 1000;
4614
  if ClientDataSetFeedsThrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4615
  then
4616
    ClientDataSetFeedsThrd_Lysd.Clear
4617
  else
4618
    ClientDataSetFeedsThrd_Lysd.Value := ClientDataSetFeedsThrd.Value / ClientDataSetFeedsLysd.Value * 100;
4619
  if ClientDataSetFeedsMetd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4620
  then
4621
    ClientDataSetFeedsMetd_Lysd.Clear
4622
  else
4623
    ClientDataSetFeedsMetd_Lysd.Value := ClientDataSetFeedsMetd.Value / ClientDataSetFeedsLysd.Value * 100;
4624
  if ClientDataSetFeedsCysd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4625
  then
4626
    ClientDataSetFeedsCysd_Lysd.Clear
4627
  else
4628
    ClientDataSetFeedsCysd_Lysd.Value := ClientDataSetFeedsCysd.Value / ClientDataSetFeedsLysd.Value * 100;
4629
  if ClientDataSetFeedsMetCysd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4630
  then
4631
    ClientDataSetFeedsMetCysd_Lysd.Clear
4632
  else
4633
    ClientDataSetFeedsMetCysd_Lysd.Value := ClientDataSetFeedsMetCysd.Value / ClientDataSetFeedsLysd.Value * 100;
4634
  if ClientDataSetFeedsTrpd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4635
  then
4636
    ClientDataSetFeedsTrpd_Lysd.Clear
4637
  else
4638
    ClientDataSetFeedsTrpd_Lysd.Value := ClientDataSetFeedsTrpd.Value / ClientDataSetFeedsLysd.Value * 100;
4639
  if ClientDataSetFeedsIled.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4640
  then
4641
    ClientDataSetFeedsIled_Lysd.Clear
4642
  else
4643
    ClientDataSetFeedsIled_Lysd.Value := ClientDataSetFeedsIled.Value / ClientDataSetFeedsLysd.Value * 100;
4644
  if ClientDataSetFeedsVald.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4645
  then
4646
    ClientDataSetFeedsVald_Lysd.Clear
4647
  else
4648
    ClientDataSetFeedsVald_Lysd.Value := ClientDataSetFeedsVald.Value / ClientDataSetFeedsLysd.Value * 100;
4649
  if ClientDataSetFeedsLeud.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4650
  then
4651
    ClientDataSetFeedsLeud_Lysd.Clear
4652
  else
4653
    ClientDataSetFeedsLeud_Lysd.Value := ClientDataSetFeedsLeud.Value / ClientDataSetFeedsLysd.Value * 100;
4654
  if ClientDataSetFeedsPhed.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4655
  then
4656
    ClientDataSetFeedsPhed_Lysd.Clear
4657
  else
4658
    ClientDataSetFeedsPhed_Lysd.Value := ClientDataSetFeedsPhed.Value / ClientDataSetFeedsLysd.Value * 100;
4659
  if ClientDataSetFeedsTyrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4660
  then
4661
    ClientDataSetFeedsTyrd_Lysd.Clear
4662
  else
4663
    ClientDataSetFeedsTyrd_Lysd.Value := ClientDataSetFeedsTyrd.Value / ClientDataSetFeedsLysd.Value * 100;
4664
  if ClientDataSetFeedsPheTyrd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4665
  then
4666
    ClientDataSetFeedsPheTyrd_Lysd.Clear
4667
  else
4668
    ClientDataSetFeedsPheTyrd_Lysd.Value := ClientDataSetFeedsPheTyrd.Value / ClientDataSetFeedsLysd.Value * 100;
4669
  if ClientDataSetFeedsHisd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4670
  then
4671
    ClientDataSetFeedsHisd_Lysd.Clear
4672
  else
4673
    ClientDataSetFeedsHisd_Lysd.Value := ClientDataSetFeedsHisd.Value / ClientDataSetFeedsLysd.Value * 100;
4674
  if ClientDataSetFeedsArgd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4675
  then
4676
    ClientDataSetFeedsArgd_Lysd.Clear
4677
  else
4678
    ClientDataSetFeedsArgd_Lysd.Value := ClientDataSetFeedsArgd.Value / ClientDataSetFeedsLysd.Value * 100;
4679
  if ClientDataSetFeedsAlad.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4680
  then
4681
    ClientDataSetFeedsAlad_Lysd.Clear
4682
  else
4683
    ClientDataSetFeedsAlad_Lysd.Value := ClientDataSetFeedsAlad.Value / ClientDataSetFeedsLysd.Value * 100;
4684
  if ClientDataSetFeedsAspd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4685
  then
4686
    ClientDataSetFeedsAspd_Lysd.Clear
4687
  else
4688
    ClientDataSetFeedsAspd_Lysd.Value := ClientDataSetFeedsAspd.Value / ClientDataSetFeedsLysd.Value * 100;
4689
  if ClientDataSetFeedsGlud.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4690
  then
4691
    ClientDataSetFeedsGlud_Lysd.Clear
4692
  else
4693
    ClientDataSetFeedsGlud_Lysd.Value := ClientDataSetFeedsGlud.Value / ClientDataSetFeedsLysd.Value * 100;
4694
  if ClientDataSetFeedsGlyd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4695
  then
4696
    ClientDataSetFeedsGlyd_Lysd.Clear
4697
  else
4698
    ClientDataSetFeedsGlyd_Lysd.Value := ClientDataSetFeedsGlyd.Value / ClientDataSetFeedsLysd.Value * 100;
4699
  if ClientDataSetFeedsSerd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4700
  then
4701
    ClientDataSetFeedsSerd_Lysd.Clear
4702
  else
4703
    ClientDataSetFeedsSerd_Lysd.Value := ClientDataSetFeedsSerd.Value / ClientDataSetFeedsLysd.Value * 100;
4704
  if ClientDataSetFeedsProd.IsNull or ClientDataSetFeedsLysd.IsNull or (ClientDataSetFeedsLysd.Value = 0)
4705
  then
4706
    ClientDataSetFeedsProd_Lysd.Clear
4707
  else
4708
    ClientDataSetFeedsProd_Lysd.Value := ClientDataSetFeedsProd.Value / ClientDataSetFeedsLysd.Value * 100;
4709
end;
4710

    
4711
function TDataModuleDeclaration.CalcBilanElectrolytique(Na, K, Cl: Double): Double;
4712
begin
4713
  Result := (Na / 23 + K / 39 - Cl / 35.5) * 1000000;
4714
  if FormOptions.Expression = 0
4715
  then // sur frais
4716
    Result := Result * RapMS;
4717
end;
4718

    
4719
function TDataModuleDeclaration.InputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
4720
begin
4721
  if ProximalUnit = 0
4722
  then // %
4723
    Result := Value / 100
4724
  else // g/kg
4725
    Result := Value / 1000;
4726
  if ExpressionMode = 0
4727
  then // sur frais
4728
    Result := Result / MS;
4729
end;
4730

    
4731
function TDataModuleDeclaration.InputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
4732
begin
4733
  if EnergyUnit = 0
4734
  then // MJ/kg
4735
    Result := Value
4736
  else // kcal/kg
4737
    Result := Value * CALORIE / 1000;
4738
  if ExpressionMode = 0
4739
  then // sur frais
4740
    Result := Result / MS;
4741
end;
4742

    
4743
function TDataModuleDeclaration.InputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
4744
begin
4745
  if AAUnit = 0
4746
  then // %
4747
    Result := Value / MAT / 100
4748
  else // g/kg
4749
    Result := Value / MAT / 1000;
4750
  if ExpressionMode = 0
4751
  then // sur frais
4752
    Result := Result / MS;
4753
end;
4754

    
4755
function TDataModuleDeclaration.InputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
4756
begin
4757
  if MineralsUnit = 0
4758
  then // %
4759
    Result := Value / 100
4760
  else // g/kg
4761
    Result := Value / 1000;
4762
  if ExpressionMode = 0
4763
  then // sur frais
4764
    Result := Result / MS;
4765
end;
4766

    
4767
function TDataModuleDeclaration.InputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
4768
begin
4769
  if IncorporationUnit = 0
4770
  then // %
4771
    Result := Value / 100
4772
  else // g/kg
4773
    Result := Value / 1000;
4774
end;
4775

    
4776
function TDataModuleDeclaration.OutputProximal(Value, MS: Double; ExpressionMode, ProximalUnit: Integer): Double;
4777
begin
4778
  if ProximalUnit = 0
4779
  then // %
4780
    Result := Value * 100
4781
  else // g/kg
4782
    Result := Value * 1000;
4783
  if ExpressionMode = 0
4784
  then // sur frais
4785
    Result := Result * MS;
4786
end;
4787

    
4788
function TDataModuleDeclaration.OutputEnergy(Value, MS: Double; ExpressionMode, EnergyUnit: Integer): Double;
4789
begin
4790
  if EnergyUnit = 0
4791
  then // MJ/kg
4792
    Result := Value
4793
  else // kcal/kg
4794
    Result := Value / CALORIE * 1000;
4795
  if ExpressionMode = 0
4796
  then // sur frais
4797
    Result := Result * MS;
4798
end;
4799

    
4800
function TDataModuleDeclaration.OutputAA(Value, MAT, MS: Double; ExpressionMode, AAUnit: Integer): Double;
4801
begin
4802
  if AAUnit = 0
4803
  then // %
4804
    Result := Value * MAT * 100
4805
  else // g/kg
4806
    Result := Value * MAT * 1000;
4807
  if ExpressionMode = 0
4808
  then // sur frais
4809
    Result := Result * MS;
4810
end;
4811

    
4812
function TDataModuleDeclaration.OutputMinerals(Value, MS: Double; ExpressionMode, MineralsUnit: Integer): Double;
4813
begin
4814
  if MineralsUnit = 0
4815
  then // %
4816
    Result := Value * 100
4817
  else // g/kg
4818
    Result := Value * 1000;
4819
  if ExpressionMode = 0
4820
  then // sur frais
4821
    Result := Result * MS;
4822
end;
4823

    
4824
function TDataModuleDeclaration.OutputIncorporation(Value: Double; IncorporationUnit: Integer): Double;
4825
begin
4826
  if IncorporationUnit = 0
4827
  then // %
4828
    Result := Value * 100
4829
  else // g/kg
4830
    Result := Value * 1000;
4831
end;
4832

    
4833
function TDataModuleDeclaration.StrTrunc(S: String; Max: Integer): String;
4834
var
4835
  l, r: Integer;
4836
begin
4837
  if ElementToCharLen(S, Length(S)) > Max
4838
  then // Cut string S to Max chars
4839
  begin
4840
    l := Max div 2;
4841
    r := Max - l - 3;
4842
    Result := AnsiLeftStr(S, l) + '...' + AnsiRightStr(S, r);
4843
  end
4844
  else
4845
    Result := S;
4846
end;
4847

    
4848
end.