【发布时间】:2017-04-07 14:58:57
【问题描述】:
Formulae: array [1..6] of TJPEGImage;
我有一个数组,我想将图像分配到其中,以便将它们显示到表单上。我使用了来自JPEG data-stream to TImage 问题的类似代码,但我在 if 语句中收到了访问冲突错误消息
procedure Tfrm_calc2.ChangeDisplay(ImgNo: Integer; NewImage: Boolean);
var
TempImg: TJPEGImage;
begin
TempImg:= TJPEGImage.Create;
TempImg.LoadFromFile('C2F'+inttostr(ImgNo)+'.jpg');
img_Formulae.Picture.Assign(TempImg);
// assigning each picture to an element in array if it is the first time. This will be used to save the pictures later on
If NewImage = True then Formulae[ImgNo].Assign(TempImg);
TempImg.Free;
ImgDisplayed:= ImgNo;
lbl_FormulaDisplay.Caption:= 'Formula ' + inttostr(ImgNo); //user can see which formula can be seen
end;
谢谢。
【问题讨论】:
-
Formulae数组是否包含初始化的TJpegImage对象? -
Assign 方法将信息从一个实例传输到另一个实例。它不会创建新实例。公式数组的元素需要在某处实例化。
-
不,它没有,我该怎么做?
-
除了提出的解决方案之外,我建议您研究泛型的使用...在大多数情况下,TObjectList
可能是比数组更好的解决方案。这并不能避免在调用它们的 Assign 方法之前初始化对象;)
标签: delphi jpeg access-violation assign timage