1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
var
{
on deporte stR et stC en dehors de la boucle, on les initialises
directement à la declaration.
}
stR : array[0..144] of extended = (
1, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2, 10, 11, 12,
13, 15, 16, 18, 20, 22, 24, 27, 30, 33, 36, 39, 43, 47, 51, 56, 62, 68,
75, 82, 91, 100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300,
330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910, 1000, 1100,
1200, 1300, 1500, 1600, 1800, 2000, 2200, 2400, 2700, 3000, 3300, 3600,
3900, 4300, 4700, 5100, 5600, 6200, 6800, 7500, 8200, 9100, 10000,
11000, 12000, 13000, 15000, 16000, 18000, 20000, 22000, 24000, 27000,
30000, 33000, 36000, 39000, 43000, 47000, 51000, 56000, 62000, 68000,
75000, 82000, 91000, 100000, 110000, 120000, 130000, 150000, 160000,
180000, 200000, 220000, 240000, 270000, 300000, 330000, 360000, 390000,
430000, 470000, 510000, 560000, 620000, 680000, 750000, 820000, 910000,
1000000, 1200000, 1500000, 1800000, 2200000, 2700000, 3300000, 3900000,
4700000, 5600000, 6800000, 8200000, 10000000
);
stC : array[0..22] of extended = (
1, 1.5, 2.2, 2.7, 3, 3.3, 3.9, 4.7, 6.8, 8.2, 10, 12, 15, 22, 33, 47,
68, 100, 150, 220, 330, 470, 680
);
procedure TForm15.Button1Click(Sender: TObject);
var
i,j,k : Integer;
hstC, hstR: Integer;
T,TH,TB : Extended;
DutyCycle : Extended;
begin
{
on utilise high() et pas Length()-1
on mets les valeurs en "cache" pour eviter les calls sur
high dans les for
}
hstC := high(stC);
hstR := high(stR);
// on bloque le refresh de memo1, rafraîchir c'est mourir!
Memo1.Lines.BeginUpdate;
try
// on vide memo1
Memo1.Clear;
for i := 0 to hstC do // 145
for j := 0 to hstR do // * 23
for k := 0 to hstR do // * 23 = 76 705 itérations
begin
TH := 0.693 * (stR[k] + stR[j]) * stC[i] * 0.000001;
TB := 0.693 * stR[k] * stC[i] * 0.000001;
T := TH + TB;
DutyCycle := (TH / (TH + TB)) * 100;
if ((TH >= 1.06) and (TH <= 1.08)) and
((TB >= 1.06) and (TB <= 1.08)) and
((DutyCycle >= 49) and (DutyCycle <= 51)) then
begin
{
format au lieu de nombreux FloatToStr
evite 7 calls qui ralentissent la boucle
}
Memo1.Lines.Add(
format('R1=%g Ω, R2=%g Ω, C1=%g µF, TH=%.3f s, TB=%.3f s, T=%.3f, Rapport Cyclique=%.2f%%',
[stR[j], stR[k], stC[i], TH, TB, T, DutyCycle])
);
{
on appel pas processmessage ... trop lent, inutile.
on appel encore moins le refresh de memo1 ... inutile également
}
end;
end;
finally
// Un appel à EndUpdate suffit à afficher la liste.
Memo1.Lines.EndUpdate;
end;
end; |
Partager