The problem is that you are effectively doing this:
var
imageVariable: TImage;
begin
imageVariable.Create (ParentForm);
end;
Which is wrong because "Create" method is being called on the variable which hasn't been assigned yet.
You should do this:
var
imageVariable: TImage;
begin
imageVariable := TImage.Create (ParentForm);
try
//use the object
finally
FreeAndNil (imageVariable);
end;
end;
Or more specifically in your code:
for Loop := 1 to 10 do
begin
ArrayOfImages[Loop] := TImage.Create (Self);
end;
Don't forget to free the objects
EDIT: Accepting @andiw's comment and taking back the tip of freeing objects.
EDIT2: Accepting @Gerry's comment and using Self as owner.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…