Delphi线程的初级应用

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
viewRadio_th线程函数在form外生命全局变量、函数内相应的局部变量可以接收全局变量的赋值进行操作、query等可以自行创建进行查询、这样结果不会改变。
 
//下面是后台发送字幕的线程函数应用。
 
……
 
var
  ldate,ldatetime:string;
  lHandle:thandle;
  dloopThreadID:dword;
  message_form: Tmessage_form;
  function viewRadio_th(P:pointer):Longint;stdcall;
 
implementation
uses commonDM, ubox_c, common_u, loginform;
 
……
 
//调用线程
 
lHandle := CreateThread(nil,0,@viewRadio_th,nil,0,dloopThreadID);
 
//线程函数
 
function viewRadio_th(P:pointer):Longint;stdcall;
 
var lquery,lnumquery:Toraquery;
    I,j: Integer;
    th_date,th_datetime:string;
    th_handle:thandle;
    th_loopThreadID:dword;
    maxnum,boxid,boxip:string;
    F:Textfile;
begin
  th_date:=ldate;
  th_datetime:=ldatetime;
  th_handle:=lhandle;
  th_loopThreadID:=dloopThreadID;
  lquery:=Toraquery.Create(nil);
  lnumquery:=toraquery.Create(nil);
  lquery.FetchAll:=true;
  lnumquery.Session:=common_dm.common_session;
  lquery.Session:=common_dm.common_session;
  with lnumquery do
  begin
    close;
    sql.Clear;
    sql.Add(‘select max(promotesalesplaynumber) maxnum from promotesales_t where PROMOTESALESTYPE=‘‘?¤??‘‘ and ‘‘‘+
    th_date+‘ ‘‘||PROMOTESALESPLAYTIME=‘‘‘+th_datetime+‘‘‘‘);
    open;
  end;    // with
  if lnumquery.RecordCount<>0 then
    maxnum:=lnumquery[‘maxnum‘];
  with lquery do
  begin
    close;
    sql.Clear;
    sql.Add(‘select * from promotesales_t where PROMOTESALESTYPE=‘‘?¤??‘‘ and ‘‘‘+
    th_date+‘ ‘‘||PROMOTESALESPLAYTIME=‘‘‘+th_datetime+‘‘‘‘);
    open;
  end;    // with
  for I := 1 to strtoint(maxnum) do    // Iterate
  begin
    lquery.First;
    if i<>1 then
      sleep(60000);
    for j := 0 to lquery.RecordCount - 1 do    // Iterate
    begin
      if strtoint(lquery[‘promotesalesplaynumber‘])>=i then
      begin
        boxid:=lquery[‘promoteboxid‘];
        with lnumquery do
        begin
           Close;
           SQL.Clear;
           SQL.Add(‘select * from BOX_T where BOXID=‘‘‘+boxid+‘‘‘‘);
           Open;
        end;    // with
        boxip:=lnumquery[‘boxip‘];
        if fileExists(common_u.fileaddress(boxip,‘radioroot‘)+‘.tit‘) then
          Deletefile(common_u.fileaddress(boxip,‘radioroot‘)+‘.tit‘);
        AssignFile(F, common_u.fileaddress(boxip,‘radioroot‘)+‘.tit‘); {??????????±??? F ????}
        ReWrite(F);
        Writeln(F, ‘[Parameter]‘+#13+‘Delay=0‘+#13+‘IntoDelay=0‘+#13+#13+‘[TextAdOsd]‘+
        #13+‘PlayMode=RIGHT_IN_LEFT_OUT‘+#13+‘Type=Text‘+#13+‘Font=????‘+#13+‘FontSize=40‘+#13+‘LoopTime=1‘+#13+‘Speed=5‘
        +#13+‘Delay=0‘+#13+‘Time=0‘+#13+‘ForegroundColor=255 255 0‘+#13+‘BackgroundColor=0 0 0‘+#13+‘UseShadow=y‘+#13+‘ShadowColor=255 0 0‘
        +#13+‘ShadowDelta=1 1‘+#13+‘cmd=first‘+#13+‘Text=‘+lquery[‘PROMOTESALESCONTENT‘]);
        Closefile(F); {??±????? F}
      end;
      lquery.Next;
    end;    // for
 
  end;    // for
  lquery.Free;
  lnumquery.Free;
  if th_handle<>0 then
    TerminateThread(th_handle,th_loopThreadID);
end;

  

Delphi线程的初级应用

上一篇:C#中char[]与string之间的转换


下一篇:linux下运行《UNIX环境高级编程》的第一个程序时源码编译出错的处理方法