Posted by 씨익

rc

 | 문서
2007.07.23 17:29
rc
Posted by 씨익
작성자   : 김태선
델마당 펌....


unit Unit1;

interface

uses
 Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
 Dialogs, StdCtrls;

type
 TForm1 = class(TForm)
   Button1: TButton;
   Button2: TButton;
   procedure Button1Click(Sender: TObject);
   procedure Button2Click(Sender: TObject);
 private
   { Private declarations }
 public
   { Public declarations }
   procedure TestFunc(Sender: TObject);
 end;

 //---------------------------------------------------------------------------
 { TRunThread }

   TRunThread = class(TThread)
   private
       OnEvent: TNotifyEvent;
       Sender: TObject;
   public
       constructor Create(event: TNotifyEvent; _sender: TObject);
       procedure Execute(); override;
   end;
 //---------------------------------------------------------------------------

var
 Form1: TForm1;

implementation

{$R *.dfm}

//---------------------------------------------------------------------------
{ TRunThread }

constructor TRunThread.Create(event: TNotifyEvent; _sender: TObject);
begin
 inherited Create(false);
 FreeOnTerminate := true;
 OnEvent := event;
 Sender := _sender;
end;

procedure TRunThread.Execute;
begin
 OnEvent(Sender);
end;

//---------------------------------------------------------------------------

{ Test }

// 요건  쓰레드에 실어서 실행할 함수 입니다.

procedure TForm1.TestFunc(Sender: TObject);
var
 c, k, temp: integer;
begin
 // 엄청 시간이 걸리는 루틴.
 for c := 0 to 1999999998 do begin
   k := c;
   inc(k);
   temp := k;
   dec(temp);
   k := temp + 1;
 end;
 Caption := inttostr(k);
 Button1.Enabled := true;
end;

// 쓰레드를 생성한후 쓰레드에서 함수를 실행한후 즉시 리턴해 프로그램 실행을 계속한다.

procedure TForm1.Button1Click(Sender: TObject);
var
 thread: TRunThread;
begin
 //
 Button1.Enabled := false;
 Caption := '1';
 thread := TRunThread.Create(TestFunc, Sender);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 //
 Caption := '하하하';
end;


end.
Posted by 씨익

procedure AddLogMsg(const AMsg : string);
var
   nLen: integer;
begin
   nLen := Length(AMsg) + 1;
   AMsg := AMsg + #0;

   with CopyData do
   begin
      cbData := nLen;
      lpData := pChar(AMsg);
   end;

   SendMessage(gMainWnd, WM_COPYDATA, 0, LongInt(@CopyData));
end;

procedure WMCopyData(var Msg: TMessage); message WM_CopyData;

procedure TMainFrame.WMCopyData(var Msg: TMessage);
begin
   if Msg.WParam = 0 then
   begin
      slLogString.add(pChar(pCopyDataStruct(Msg.lParam)^.lpData));
      slLogString.SaveToFile(gLocalLogFile);
   end;
end;

Posted by 씨익