我刚开始学习线程,还什么都不会呢,希望大家多帮忙,请问应该怎么实现这样的程序结构
1.我有一个工程,我想在创建工程前调用一个线程,如果这个线程执行后计算的值是1就不进入此工程
2.退出工程的时候清理掉此线程

解决方案 »

  1.   

    program Project1;uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1};{$R *.res}begin
     if myProc = 1 then 
      begin
        Application.Initialize;
        Application.CreateForm(TForm1, Form1);
        Application.Run;
      end;
    end.
      

  2.   

    是用于软件狗加密么?如果是用下面的代码实现启动检测,启动后再用线程检测吧。program Project1; uses 
      Forms, 
      Unit1 in 'Unit1.pas' {Form1}; {$R *.res} begin 
    if myProc = 1 then 
      begin 
        Application.Initialize; 
        Application.CreateForm(TForm1, Form1); 
        Application.Run; 
      end; 
    end.
      

  3.   

    问一下,if myProc = 1 then 
    是怎么得来的,能写点具体的代码吗?在线程方面我是个初学者
      

  4.   


    //工程文件
    program Project1;uses
      Forms,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas'; {TTesthread}var
      Test: TTestThread;{$R *.res}begin
      R := 0;
      Test := TTestThread.Create(False);
      Test.WaitFor;
      if R = 1 then
      begin
        Application.Initialize;
        Application.CreateForm(TForm1, Form1);
        Application.Run;
      end;
    end.//线程单元
    unit Unit2;interfaceuses
      Classes;type
      TTestThread = class(TThread)
      protected
        procedure Execute; override;
      end;implementationprocedure TTestThread.Execute;
    begin
      R := 1; //你在这里判断后再给R赋值到底是0还是1。
    end;end.
    这就是你想要的了. 给你写好代码了. 发帖急需分啊......
      

  5.   

    其实这跟线程同步没关闭. 
    关键在与Test.WaitFor;
    就是等待线程执行完了才继续执行下面的代码.
      

  6.   

    抱歉. 上面写太快忘了行代码. 重新发下. 
    //工程文件
    program Project1;uses
      Forms,
      Windows,
      Unit1 in 'Unit1.pas' {Form1},
      Unit2 in 'Unit2.pas'; {TTesthread}var
      Test: TTestThread;{$R *.res}begin
      R := 0;
      Test := TTestThread.Create(False);
      Test.WaitFor;
      if R = 1 then
      begin
        Application.Initialize;
        Application.CreateForm(TForm1, Form1);
        Application.Run;
      end;
    end.//线程单元
    unit Unit2;interfaceuses Windows, Classes;type
      TTestThread = class(TThread)
      protected
        procedure Execute; override;
      end;var
      R: DWORD;implementationprocedure TTestThread.Execute;
    begin
      R := 1; //你在这里判断后再给R赋值到底是0还是1。
    end;end.