F
fjpan
Unregistered / Unconfirmed
GUEST, unregistred user!
unit padlock;
interface
uses
windows;
type tsepadlock = class
private
fcritsect: trtlcriticalsection;
protected
procedure setlocked(l: boolean);
public
constructor create;
destructor destroy ;
override;
property locked :boolean write setlocked;
end;
implementation
constructor tsepadlock.create;
begin
initializecriticalsection(fcritsect);
end;
destructor tsepadlock.destroy;
begin
deletecriticalsection(fcritsect);
end;
procedure tsepadlock.setlocked(l:boolean);
begin
if l then
entercriticalsection(fcritsect)
else
leavecriticalsection(fcritsect);
end;
end.
program testpadlock;
{$apptype console }
{$define usepadlock}
uses
sysutils,
windows,
padlock;
var consolepadlock :tsepadlock;
procedure safewriteln(const s:string);
begin
{$ifdef usepadlock}
consolepadlock.locked:=true;
try
writeln(s);
finally
consolepadlock.locked:=false;
end;
{$else
}
writeln(s);
{$endif}
end;
function englishthreadroutine(Pointer):integer;
var
threadid: integer ;
i: integer;
begin
result:=0;
threadid:=getcurrentthreadid;
for i:=1 to 20do
safewriteln(format('[%x] current line: %d' , [threadid,i]));
end;
function frenchthreadroutine(pointer):integer;
var
threadid:integer;
i : integer;
begin
result:=0;
threadid:= getcurrentthreadid;
for i:=1 to 20do
safewriteln(format('[%x] ligne courant : %d',[threadid, i]));
end;
var
handles: array[0..1] of integer ;
threadid: integer ;
begin
fillchar(handles,sizeof(handles),0);
consolepadlock:=tsepadlock.create;
engthr:= englishthreadroutine;
frenthr:= frenchthreadroutine;
try
handles[0]:=begin
thread(nil,0,englishthreadroutine,nil,0,threadid);
handles[1]:=begin
thread(nil,0,frenchthreadroutine,nil,0,threadid);
waitformultipleobjects(2,@handles,true,infinite);
finally
if (handles[0]<>0) then
closehandle(handles[0]);
if (handles[1]<>0) then
closehandle(handles[1]);
consolepadlock.free;
end;
writeln('press<enter> to close...');
readln;
end.
程序运行到了
handles[0]:=begin
thread(nil,0,englishthreadroutine,nil,0,threadid);
handles[1]:=begin
thread(nil,0,frenchthreadroutine,nil,0,threadid);
就有For a variable parameter, the actual argument must be of the exact type of the formal parameter.
why?
plz help me
interface
uses
windows;
type tsepadlock = class
private
fcritsect: trtlcriticalsection;
protected
procedure setlocked(l: boolean);
public
constructor create;
destructor destroy ;
override;
property locked :boolean write setlocked;
end;
implementation
constructor tsepadlock.create;
begin
initializecriticalsection(fcritsect);
end;
destructor tsepadlock.destroy;
begin
deletecriticalsection(fcritsect);
end;
procedure tsepadlock.setlocked(l:boolean);
begin
if l then
entercriticalsection(fcritsect)
else
leavecriticalsection(fcritsect);
end;
end.
program testpadlock;
{$apptype console }
{$define usepadlock}
uses
sysutils,
windows,
padlock;
var consolepadlock :tsepadlock;
procedure safewriteln(const s:string);
begin
{$ifdef usepadlock}
consolepadlock.locked:=true;
try
writeln(s);
finally
consolepadlock.locked:=false;
end;
{$else
}
writeln(s);
{$endif}
end;
function englishthreadroutine(Pointer):integer;
var
threadid: integer ;
i: integer;
begin
result:=0;
threadid:=getcurrentthreadid;
for i:=1 to 20do
safewriteln(format('[%x] current line: %d' , [threadid,i]));
end;
function frenchthreadroutine(pointer):integer;
var
threadid:integer;
i : integer;
begin
result:=0;
threadid:= getcurrentthreadid;
for i:=1 to 20do
safewriteln(format('[%x] ligne courant : %d',[threadid, i]));
end;
var
handles: array[0..1] of integer ;
threadid: integer ;
begin
fillchar(handles,sizeof(handles),0);
consolepadlock:=tsepadlock.create;
engthr:= englishthreadroutine;
frenthr:= frenchthreadroutine;
try
handles[0]:=begin
thread(nil,0,englishthreadroutine,nil,0,threadid);
handles[1]:=begin
thread(nil,0,frenchthreadroutine,nil,0,threadid);
waitformultipleobjects(2,@handles,true,infinite);
finally
if (handles[0]<>0) then
closehandle(handles[0]);
if (handles[1]<>0) then
closehandle(handles[1]);
consolepadlock.free;
end;
writeln('press<enter> to close...');
readln;
end.
程序运行到了
handles[0]:=begin
thread(nil,0,englishthreadroutine,nil,0,threadid);
handles[1]:=begin
thread(nil,0,frenchthreadroutine,nil,0,threadid);
就有For a variable parameter, the actual argument must be of the exact type of the formal parameter.
why?
plz help me