The problem is that you are effectively doing this:
var imageVariable: TImage; begin imageVariable.Create (ParentForm); end;
This is incorrect because the Create method is called in a variable that has not yet been assigned.
You must 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;
Do not forget to free objects
EDIT: Accept @andiw comment and return the end of the release of objects. EDIT2: Accepting @Gerry's comment and using Self as owner.
source share