Ich habe heute begonnen mit Lazarus zu programmieren.
Nun habe ich einen Programmablauf erstellt, der für 9 verschiedene Objekte das gleiche ausführt. Ich wollte das ganze nun in eine Funktion auslagern, damit ich nicht so viel Code habe und ich Änderungen im Ablauf nicht in alle 9 Routinen übertragen muss.
Nur leider weiß ich nicht, wie ich auf die einzelnen Objekte per Variable zugreifen kann

Bsp:
Code: Alles auswählen
if CheckBox1.Checked then begin
if Skip1 = true then
else begin
Shape1.top := round(move(g1,timeT));
if ypTemp + 10 > Form1.clientHeight then begin
Shape1.top := Form1.clientHeight -10 ;
Skip1 := true;
LTime1.Caption := FloatToStr(timeT);
LTime1.Top := Shape1.top - 20;
LTime1.Visible := true;
end;
end;
end;
if CheckBox2.Checked then begin
if Skip2 = true then
else begin
Shape2.top := round(move(g2,timeT));
if ypTemp + 10 > Form1.clientHeight then begin
Shape2.top := Form1.clientHeight -10 ;
Skip2 := true;
LTime2.Caption := FloatToStr(timeT);
LTime2.Top := Shape2.top - 20;
LTime2.Visible := true;
end;
end;
end;
Code: Alles auswählen
if CheckBox1.Checked then begin
FunctionXYZ('Shape1','LTime1','Skip1','g1');
end;
if CheckBox2.Checked then begin
FunctionXYZ('Shape2','LTime2','Skip2','g2');
end;
end;
function FunctionXYZ(var a,b,c,d: String);
begin
%a%.top := round(move(%d%,timeT));
if ypTemp + 10 > Form1.clientHeight then begin
%a%.top := Form1.clientHeight -10 ;
%c% := true;
%b%.Caption := FloatToStr(timeT);
%b%.Top := Shape1.top - 20;
%b%.Visible := true;
end;
end;

Gruß, flashkid