want to run nested loop in thread its running but when we will select multiple images its getting stucked and memory overload issue coming also sometime after application closed getting access voilation error
please help in below code
procedure test.Execute;
var
pathis,Selected,pathimodelname,pathi,path : string;
topwid,tophid,iSelIndex,indexofmview,faf, i,j: Integer;
selList: TIEArrayOfInteger;
foldername: string;
begin
Form1.ImageEnMView1.MultiSelectedImagesAutoSort := False;
Form1.ImageEnMView2.MultiSelectedImagesAutoSort := False;
Form1.ImageEnView1.ClearAll;
// ProgressBar1.Min := 0;
// ProgressBar1.Max := ListBox1.Items.Count - 1;
// ProgressBar1.Position := 0;
try
begin
try
Form1.ProgressBar2.Min := i;
Form1.ProgressBar2.Max := Form1.ImageEnMView2.ImageCount;
Form1.ProgressBar2.Position := 0;
Form1.ProgressBar2.Step := 1;
finally
end;
end;
begin
try
Form1.ProgressBar1.Min := j;
Form1.ProgressBar1.Max := Form1.ImageEnMView1.ImageCount;
Form1.ProgressBar1.Position := 0;
Form1.ProgressBar1.Step := 1;
finally
end;
end;
begin
for j := 0 to Form1.ImageEnMView1.ImageCount - 1 do
if Form1.ImageEnMView1.Checked[j] then
begin
Form1.ImageEnView1.ClearAll;
//Form1.ImageEnView1.LayersInsert(0,Form1.ImageEnMView1.ImageFileName[j],0,0);
Form1.ImageEnView1.Fit(True);
Form1.ImageEnView1.Update;
//ShowMessage(Form1.ImageEnMView1.ImageFileName[j]);
begin
try
Form1.ImageEnView1.LayersInsert(0,Form1.ImageEnMView1.ImageFileName[j],0,0);
pathimodelname := ( TPath.GetFileNameWithoutExtension(Form1.ImageEnMView1.ImageFileName[j]));
begin
Form1.ProgressBar1.StepIt;
Form1.ProgressBar1.Update;
end;
//ShowMessage(pathimodelname);
begin
if not TDirectory.Exists(Form1.edit2.Text+'\'+pathimodelname) then
TDirectory.CreateDirectory(Form1.edit2.Text+'\'+pathimodelname);
foldername := (Form1.edit2.Text+'\'+pathimodelname+'\');
//ShowMessage('pathfoldername'+' '+foldername);
end;
topwid:= Form1.ImageEnView1.CurrentLayer.Width;
tophid:= Form1.ImageEnView1.CurrentLayer.Height;
Form1.ImageEnView1.CurrentLayer.Name := 'top';
Form1.ImageEnView1.Fit(True);
Form1.ImageEnView1.Update;
finally
end;
begin
for i := 0 to Form1.ImageEnMView2.ImageCount - 1 do
//if Form1.ImageEnMView1.IsSelected(i) then
if Form1.ImageEnMView2.Checked[i] then
begin
//iSelIndex := Form1.ImageEnMView1.MultiSelectedImages[ i ];
//Form1.ImageEnView1.LayersInsert(0,Form1.ImageEnMView1.ImageFileName[i],0,0);
//Form1.ImageEnView1.LayersInsert(1,Form1.ImageEnMView2.ImageFileName[i],0,0);
//Form1.ImageEnView1.LayersRemove(1);
//Form1.ImageEnView1.IO.LoadFromFile(Form1.ImageEnMView2.ImageFileName[i]);
Form1.ImageEnView1.LayersAdd( Form1.ImageEnMView2.ImageFileName[i],0,0 );
Form1.ImageEnView1.CurrentLayer.Width := topwid;
Form1.ImageEnView1.CurrentLayer.Height := tophid;
pathi := ( TPath.GetFileNameWithoutExtension(Form1.ImageEnMView2.ImageFileName[i]));
//ShowMessage(pathi);
{without folder name}
//pathis := ( Form1.edit2.Text+'\'+pathi+' '+pathimodelname+'.png');
{with folder name}
pathis := ( foldername+'\'+pathi+' '+pathimodelname+'.png');
//ShowMessage(pathis);
//ShowMessage(pathi);
//Form1.ImageEnView1.LayersInsert(1, Form1.ImageEnMView2.ImageFileName[i],0,0 );
Form1.ImageEnView1.LayersArrange( LYR_SELECTED_LAYERS, 0 );
begin
Form1.ImageEnView1.LayersSaveMergedTo(pathis);
{
Form1.SaveImageEnDialog1.FileNameW := pathi+pathimodelname;
if Form1.SaveImageEnDialog1.Execute then
begin
//Form1.ImageEnView1.LayersSaveMergedTo(Form1.SaveImageEnDialog1.FileName);
Form1.ImageEnView1.IO.SaveToFile(pathi,ioJPEG);
end;
}
end;
Form1.ImageEnView1.LayersRemove(LYR_SELECTED_LAYERS);
//Form1.ImageEnView1.IO.LoadFromFile(Form1.ImageEnMView2.ImageFileName[i]);
//ShowMessage(Form1.ImageEnMView2.ImageFileName[i]);
Form1.ImageEnView1.Update;
Form1.ImageEnView1.Fit(True);
Form1.ImageEnView1.Update;
//ShowMessage(Form1.ImageEnMView1.ImageFileName[j]);
Form1.ProgressBar2.StepIt;
Form1.ProgressBar2.Update;
end;
end;
end;
//ShowMessage(Form1.ImageEnMView2.ImageFileName[j]);
end;
end;
finally
begin
try
ShowFolder( Form1.edit2.Text);
test.Sleep(0);
test.SpinWait(0);
finally
Free;
Form1.ProgressBar1.Free;
Form1.ProgressBar2.Free;
end;
end;
end;
Free;
end;
//above is thread procedure
/////////////////////////////
mentioned after
private
{ Private declarations }
public
{ Public declarations }
end;
test = class (TThread)
protected
procedure Execute; override;
end;
//////////////////////////
with test.Create do
FreeOnTerminate := True;