Statistiques
| Révision:

root / UnitDeclaration.pas @ 10

Historique | Voir | Annoter | Télécharger (219,598 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
  MAX_SUM = 1.15; // 115%
14
  CoefMAT = 14.73 * 100 * CALORIE / 1000;
15
  CoefMG = 52.4 * 100 * CALORIE / 1000;
16
  CoefMM = -44.6 * 100 * CALORIE / 1000;
17
  dLys = 0.770;
18
  dThr = 0.760;
19
  dMet = 0.846;
20
  dCys = 0.733;
21
  dMetCys = 0.788;
22
  dTrp = 0.772;
23
  dIle = 0.807;
24
  dVal = 0.777;
25
  dLeu = 0.833;
26
  dPhe = 0.842;
27
  dTyr = 0.855;
28
  dPheTyr = 0.847;
29
  dHis = 0.841;
30
  dArg = 0.887;
31
  dAla = 0.773;
32
  dAsp = 0.791;
33
  dGlu = 0.861;
34
  dGly = 0.718;
35
  dSer = 0.807;
36
  dPro = 0.787;
37

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

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

    
421
implementation
422

    
423
{$R *.dfm}
424

    
425
uses
426
  SHFolder, StrUtils, UnitOptions;
427

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
4849
end.