I did heavy changes, but i hope you can see what i did there:
unit Unit1;
{$mode objfpc}{$H+}
interface
uses
wincrt,intfgraphics, windows, SysUtils, FileUtil, Forms,
Controls, Graphics, LResources, Process, ExtCtrls, Dialogs, StdCtrls, LCLProc,
ActnList, LCLIntf, LCLType, Interfaces, Buttons, ExtDlgs, Menus, ComCtrls,
strutils, MMSystem, Classes, GraphType;
type
{ TMyThread }
TMyThread = class(TThread)
protected
procedure Execute; override;
public
FImage: TImage;
FFilename: string;
constructor Create(image: TImage; filename: string);
end;
{ TForm1 }
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Image2: TImage;
Image3: TImage;
procedure Button1Click(Sender: TObject);
private
{ private declarations }
public
{ public declarations }
//tempstr1:string;
end;
var
Form1: TForm1;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
TMyThread.Create(image1, 'c:\temp39\pix1.jpg');
TMyThread.Create(image2, 'c:\temp39\pix2.jpg');
TMyThread.Create(image3, 'c:\temp39\pix3.jpg');
end;
{ TForm1 }
{$R *.lfm}
constructor TMyThread.Create(image: TImage; filename: string);
begin
inherited Create(false);
FreeOnTerminate:=true;
FImage:=image;
FFilename:=filename;
end;
procedure TMyThread.Execute;
var AJpg: TJpegImage;
begin
AJpg := TJpegImage.Create;
AJpg.LoadFromFile(FFilename);
FImage.picture.Bitmap.Assign(AJpg);
AJpg.free;
end;
end.I didn't go as far as run it with pictures, but it compiles. You don't need synchronize in this case, with threads that are strictly limited to their own spaces. You will never have a case where 2 threads load same image at the time, unless you do that on purpose.
Well, synchronize is easy to add to this. Move AJpg to thread variables and re-create the procedure LoadImage; you had before. Bigger point is that you don't need to make a new thread class for each image, but generalize it to 1.