ich brauche noch einmal eure Hilfe. Ich möchte gerne ein Daten aus einem StringGrid verarbeitet haben. Damit ich dieselbe Berechnung nicht bei 60 verschiedenen Grids eingeben muss, möchte ich die Berechnung in eine Funktion auslagern.
Funktion:
Code: Alles auswählen
function CalcGrid(const tech, day: String):String;
var
y: integer;
h1: real;
SG1: string;
begin
h1:=0;
SG1:=('T'+tech+'_StringGrid'+day);
for y:=1 to TStringGrid(form8.FindComponent(SG1)).RowCount -1 do
begin
If StrToFloat(TStringGrid(form8.FindComponent(SG1)).Cells[0,y])>0 then
begin
TStringGrid(form8.FindComponent(SG1)).Cells[6,y] :=
FloatToStr(RoundTo(StrToFloat(TStringGrid(form8.FindComponent(SG1)).Cells[0,y])*
StrToFloat(TStringGrid(form8.FindComponent(SG1)).Cells[4,y]) / 100 *
(100-StrToFloat(TStringGrid(form8.FindComponent(SG1)).Cells[5,y])),-2));
end
else if StrtoFloat(TStringGrid(form8.FindComponent(SG1)).Cells[0,y])=0 then
TStringGrid(form8.FindComponent(SG1)).Cells[6,y] := '0';
h1:=StrToFloat(TStringGrid(form8.FindComponent(SG1)).Cells[6,y])+h1;
end;
result:=FloatToStr(h1);
end;
Code: Alles auswählen
procedure TForm8.T1_StringGrid2EditingDone(Sender: TObject);
begin
T1D2_Edit1.Text:=(CalcGrid('1','2'));
end;
Leider stürzt das Programm ohne Fehlermeldung ab. Habt ihr einen Hinweis, woran das liegen kann?
Gruß
Christian