Q&A

  • 쓰레드 실행은 되는것 같은데 화면에 출력이 안되네요. 어떻게 하면 될까요?
소스
unit ImageThreadU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComCtrls, StdCtrls, TFlatComboBoxUnit, dxButtons, dxCore,
  dxCheckCtrls, ExtCtrls, ImgPanel, ExtDlgs, ImgBox, JPEG, ImgList,
  GR32_Image, DB, ZAbstractRODataset, ZAbstractDataset, ZDataset,
  TFlatEditUnit, ToolWin, GR32_RangeBars, GR32, Grids, DBGrids, RXDBCtrl;
type
  TShowInfo = Record
    No       : Integer;
    FileName : String;
    Subject  : String;
    Comment  : String;
end;

type
  TRecInfo = Record
    Height : Integer;
    Width : Integer;
    Top : Integer;
    Left : Integer;
    Space : Integer;
    ColCount : Integer;
    NowCount : Integer;
    NowLeft : Integer;
    NowTop : Integer;
    TW : Integer;
    TH : Integer;
    LW1 : Integer;
    LH1 : Integer;
    LW2 : Integer;
    LH2 : Integer;
end;


type
  ImageThread = class(TThread)
  private
    procedure ImgCenterOnClick(Sender: TObject);
    procedure ImgCenterOnDBClick(Sender: TObject);
    procedure ShowImgLST(ImgBack:TPanel; FRec:TRecInfo);
    { Private declarations }
  protected
    procedure Execute; override;
  public
    constructor Create(T_ImgBack:TPanel);reintroduce;
  end;

var
    Rec     : TRecInfo;
    S_File   : TShowInfo;
    DrawPanel : TPanel;

implementation
uses Main_DBU, TntImageU, tntlib, ShowImageU;
{ Important: Methods and properties of objects in visual components can only be
  used in a method called using Synchronize, for example,

      Synchronize(UpdateCaption);

  and UpdateCaption could look like,

    procedure ImageThread.UpdateCaption;
    begin
      Form1.Caption := 'Updated in a thread';
    end; }

{ ImageThread }

  const
    D_Color = clBtnFace;
    A_Color = clActiveCaption;

constructor ImageThread.Create(T_ImgBack:TPanel);
begin
  DrawPanel := T_ImgBack;
  Rec.Height := 100;
  Rec.Width := 130;
  Rec.Space := 5;
  Rec.LH1 := 13;
  Rec.LH2 := 13;
  Rec.TW := (Rec.Space*2)+ Rec.Width;
  Rec.TH := (Rec.Space*2)+Rec.Height+Rec.LH1+Rec.Space;
  Inherited Create(False);
end;


procedure ImageThread.Execute;
var
  i : Integer;
begin
  { Place thread code here }
  FreeOnTerminate := True;                                      //쓰레드 종료 플래그 초기화
  with Main_DB.Img_DB do
  begin
    if RecordCount > 0 then begin
      First;
      DrawPanel.Left := 0;
      DrawPanel.Top := 0;
      DrawPanel.Width := TntImageF.Width-20;
      Rec.ColCount := TntImageF.Width div (Rec.TW+Rec.Space);
      DrawPanel.Height := (Rec.TH+(Rec.Space*2))*((RecordCount div Rec.ColCount)+1);
      Rec.NowCount := Rec.Space;
      Rec.NowTop := Rec.Space;
      Rec.NowLeft := Rec.Space;
      Rec.NowCount := 0;
      for i := DrawPanel.ControlCount-1 downto 0 do
        DrawPanel.Controls[i].Free;
      while not eof do
      begin
        S_File.No := Fieldbyname('no').AsInteger;
        S_File.FileName := Pic_Dir+'\'+Fieldbyname('filename').AsString;
        S_File.Subject := Fieldbyname('subject').AsString;
        S_File.Comment := Fieldbyname('comment').AsString;
        ShowImgLST(DrawPanel, Rec);
        if Rec.NowCount >= Rec.ColCount-1 then begin
          Rec.NowCount := 0;
          Rec.NowLeft := Rec.Space;
          Rec.NowTop := Rec.NowTop + (Rec.TH+Rec.Space);
        end else begin
          Rec.NowCount := Rec.NowCount + 1;
          Rec.NowLeft := Rec.NowLeft+ (Rec.Space+Rec.TW);
        end;

        next;
      end;
      First;
    end;
  end;

  Terminate;
end;

procedure ImageThread.ShowImgLST(ImgBack:TPanel; FRec:TRecInfo);
var
  load_File : String;
  tmpHeight, tmpWidth : integer;
  ImgPanel : TPanel;
  ImgLeft : TImage32;
  ImgCenter: TImage32;
  ImgRight : TImage32;
  Subject : TLabel;
  Comment : TLabel;
begin
  ImgPanel := TPanel.Create(ImgBack);
  ImgCenter := TImage32.Create(ImgPanel);
  ImgLeft := TImage32.Create(ImgPanel);
  ImgRight := TImage32.Create(ImgPanel);
  Subject := TLabel.Create(ImgPanel);
//  Comment := TLabel.Create(ImgPanel);
  ImgPanel.Parent := ImgBack;
  ImgPanel.Width := FRec.TW;
  ImgPanel.Height := FRec.TH;
  ImgPanel.Top := FRec.NowTop;
  ImgPanel.Left := FRec.NowLeft;
  ImgPanel.Hint := S_File.FileName;
  ImgPanel.ShowHint := False;
  ImgCenter.Left := FRec.Space;
  ImgCenter.Width := FRec.Width;
  ImgCenter.Top := FRec.Space;
  ImgCenter.Height := FRec.Height;
  ImgCenter.Cursor := crHandPoint;
  ImgCenter.Color := clWhite;
  ImgCenter.AutoSize := False;
  ImgCenter.Bitmap.StretchFilter := sfLanczos;
  ImgCenter.ScaleMode := smResize;
  ImgCenter.BitmapAlign := baCenter;
  ImgCenter.Hint := inttostr(S_File.No);
  ImgCenter.ShowHint := False;
  ImgCenter.Bitmap.LoadFromFile(S_File.FileName);
  ImgCenter.OnClick := ImgCenterOnClick;
  ImgCenter.OnDblClick := ImgCenterOnDBClick;
  ImgCenter.Parent := ImgPanel;
  Subject.Left := FRec.Space;
  Subject.Top := ImgCenter.Top+ImgCenter.Height+4;
  Subject.Width := ImgCenter.Width;
  Subject.AutoSize := False;
  Subject.Caption := StripString(S_File.Subject,18);
  Subject.Hint := S_File.Subject;
  Subject.ShowHint := True;
  Subject.Parent := ImgPanel;
end;

procedure ImageThread.ImgCenterOnClick(Sender: TObject);
var
  i : integer;
begin
  Select_Data.No := strtoint(TImage32(Sender).Hint);
  if Sender is TComponent then
  begin
    for i := 0 to TntImageF.ViewImg.ControlCount -1 do
      (TntImageF.ViewImg.Controls[i] as TPanel).Color := D_Color;
    TPanel((Sender as TImage32).Parent).Color := A_Color;
    Select_Data.FileName := TPanel((Sender as TImage32).Parent).Hint;
    for i := 0 to TPanel((Sender as TImage32).Parent).ControlCount-1 do
    begin
      if TPanel((Sender as TImage32).Parent).Controls[i] is TLabel then
        Select_Data.Subject := (TPanel((Sender as TImage32).Parent).Controls[i] as TLabel).Hint;
    end;
  end;
end;

procedure ImageThread.ImgCenterOnDBClick(Sender: TObject);
var
  i : integer;
begin
  Select_Data.No := strtoint(TImage32(Sender).Hint);
  if Sender is TComponent then
  begin
    for i := 0 to TntImageF.ViewImg.ControlCount -1 do
      (TntImageF.ViewImg.Controls[i] as TPanel).Color := D_Color;
    TPanel((Sender as TImage32).Parent).Color := A_Color;
    Select_Data.FileName := TPanel((Sender as TImage32).Parent).Hint;
    for i := 0 to TPanel((Sender as TImage32).Parent).ControlCount-1 do
    begin
      if TPanel((Sender as TImage32).Parent).Controls[i] is TLabel then
        Select_Data.Subject := (TPanel((Sender as TImage32).Parent).Controls[i] as TLabel).Hint;
    end;
  end;
  if ShowImageF <> nil then begin
    ShowImageF.BringToFront;
  end else begin
    ShowImageF := TShowImageF.Create(Application);

  end;
  ShowImageF.Caption := Select_Data.Subject;
  ShowImageF.ImgView.Bitmap.LoadFromFile(Select_Data.FileName);
  ShowImageF.Show;
end;


end.
0  COMMENTS