S
subcom
Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tbuffer = record
SrsNo:String;
Srscont:string;
Rcvtime:Tdatetime;
tag:integer;
end;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
ReadPos,WritePos:integer;
TempBuffer : array [0..255] of Tbuffer;
function MyThreadFunc(Pointer):Longint;stdcall;
function MyThreadFunc1(Pointer):Longint;stdcall;
public
InterlockedCrit : TRTLCriticalSection;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Tform1.MyThreadFunc(Pointer):Longint;stdcall;
var i:integer;
DC:HDC;S:string;
begin
DC:=GetDC(Form1.Handle);
while not application.Terminateddo
begin
EnterCriticalSection( InterlockedCrit );
if WritePos =256 then
WritePos := 0;
TempBuffer[WritePos].SrsNo := inttostr(i);
TempBuffer[WritePos].Srscont := inttostr(i);
TempBuffer[WritePos].Rcvtime := now;
edit1.Text := inttostr(i);
inc(WritePos);
inc(i);
LeaveCriticalSection( InterlockedCrit );
end;
end;
function Tform1.MyThreadFunc1(Pointer):Longint;stdcall;
var i:integer;
DC:HDC;S:string;
begin
DC:=GetDC(Form1.Handle);
while not application.Terminateddo
begin
EnterCriticalSection( InterlockedCrit );
if ReadPos =256 then
ReadPos := 0;
TempBuffer[ReadPos].SrsNo := inttostr(i);
TempBuffer[ReadPos].Srscont := inttostr(i);
TempBuffer[ReadPos].Rcvtime := now;
edit2.Text := inttostr(i);
inc(ReadPos);
inc(i);
LeaveCriticalSection( InterlockedCrit );
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var hThread:Thandle;//定义一个句柄
ThreadIDWord;
begin
//创建线程,同时线程函数被调用
hthread:=CreateThread(nil,0,@Tform1.MyThreadfunc,nil,0,ThreadID);
hthread:=CreateThread(nil,0,@Tform1.MyThreadfunc1,nil,0,ThreadID);
end;
end.
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
Tbuffer = record
SrsNo:String;
Srscont:string;
Rcvtime:Tdatetime;
tag:integer;
end;
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
ReadPos,WritePos:integer;
TempBuffer : array [0..255] of Tbuffer;
function MyThreadFunc(Pointer):Longint;stdcall;
function MyThreadFunc1(Pointer):Longint;stdcall;
public
InterlockedCrit : TRTLCriticalSection;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Tform1.MyThreadFunc(Pointer):Longint;stdcall;
var i:integer;
DC:HDC;S:string;
begin
DC:=GetDC(Form1.Handle);
while not application.Terminateddo
begin
EnterCriticalSection( InterlockedCrit );
if WritePos =256 then
WritePos := 0;
TempBuffer[WritePos].SrsNo := inttostr(i);
TempBuffer[WritePos].Srscont := inttostr(i);
TempBuffer[WritePos].Rcvtime := now;
edit1.Text := inttostr(i);
inc(WritePos);
inc(i);
LeaveCriticalSection( InterlockedCrit );
end;
end;
function Tform1.MyThreadFunc1(Pointer):Longint;stdcall;
var i:integer;
DC:HDC;S:string;
begin
DC:=GetDC(Form1.Handle);
while not application.Terminateddo
begin
EnterCriticalSection( InterlockedCrit );
if ReadPos =256 then
ReadPos := 0;
TempBuffer[ReadPos].SrsNo := inttostr(i);
TempBuffer[ReadPos].Srscont := inttostr(i);
TempBuffer[ReadPos].Rcvtime := now;
edit2.Text := inttostr(i);
inc(ReadPos);
inc(i);
LeaveCriticalSection( InterlockedCrit );
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var hThread:Thandle;//定义一个句柄
ThreadIDWord;
begin
//创建线程,同时线程函数被调用
hthread:=CreateThread(nil,0,@Tform1.MyThreadfunc,nil,0,ThreadID);
hthread:=CreateThread(nil,0,@Tform1.MyThreadfunc1,nil,0,ThreadID);
end;
end.