小弟我是新手看不大明白啊,能详细说说吗?特别是它如何实现随机抽奖的,谢谢!万分感激~  AssignFile(BaseFile,TextEdit.Text);
  Reset(BaseFile);
  BaseLen:=0;
  While not eof(BaseFile) do
  begin
    Readln(BaseFile,BaseStr);
    BaseLen:=BaseLen+1;
  end;
  CloseFile(BaseFile);
  pickno:=StrToInt(SpinEdit1.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit4.Text);
  if pickno=0 then
  begin
    ShowMessage('您设的抽奖数量为0,程序不能执行下去!');
    Exit;
  end;  if PickNo>BaseLen then
  begin
    ShowMessage('文本文件中的资料只有'+IntToStr(BaseLen)+'行,您设置的抽奖数量却为'+IntToStr(PickNo)+'!  请重新设置。');
    Exit;
  end;  Gauge.Progress:=0;
  for I:=1 to PickNo do
  begin
    Gauge.Progress:=50*I Div PickNo;
    j:=0;
    randomize;
    RandomBaseLen:=Random(BaseLen)+1;
    while J<I do
    begin
      if inttostr(RandomBaseLen)<>Pick[J] then
        J:=J+1
      else
      begin
        Randomize;
        RandomBaseLen:=Random(BaseLen)+1;
        J:=0
      end;
    end;
    Pick[I]:=IntToStr(RandomBaseLen);
  end;  AssignFile(BaseFile,TextEdit.Text);
  Reset(BaseFile);AssignFile(BaseFile,TextEdit.Text);
  Reset(BaseFile);
  for J:=1 to BaseLen do
  begin
    Gauge.Progress:=50+50*J Div BaseLen;
    Readln(BaseFile,BaseStr);
    for I:=1 to PickNo do
    begin
    if IntToStr(J)=Pick[I] then
      begin
        if I<=StrToInt(SpinEdit1.Text) then
        begin
          PickStr[I]:=BaseStr;
          break;
        end;
        if (I<=StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I>StrToInt(SpinEdit1.Text)) then
        begin
          PickStr[I]:=BaseStr;
          break;
        end;
        if (I<=StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I>StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) then
        begin
          PickStr[I]:=BaseStr;
          break;
        end;
        if (I<=StrToInt(SpinEdit4.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I>StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) then
        begin
          PickStr[I]:=BaseStr;
          break;
        end;
      end;
    end;
  end;
  CloseFile(BaseFile); 

解决方案 »

  1.   

    AssignFile(BaseFile,TextEdit.Text); 
      Reset(BaseFile); 
      BaseLen:=0; 
      While not eof(BaseFile) do 
      begin 
        Readln(BaseFile,BaseStr); 
        BaseLen:=BaseLen+1; //看看文件有多少行
      end; 
      CloseFile(BaseFile);   //取得抽奖数量,如果为0则退出,4个SpinEdit1里是什么,暂时还不知道,应该是和数量有关系的东西吧
      pickno:=StrToInt(SpinEdit1.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit4.Text); 
      if pickno=0 then 
      begin 
        ShowMessage( '您设的抽奖数量为0,程序不能执行下去! '); 
        Exit; 
      end;   if PickNo >BaseLen then //设定抽奖数量必须大于行数,具体什么资料,还不知道
      begin 
        ShowMessage( '文本文件中的资料只有 '+IntToStr(BaseLen)+ '行,您设置的抽奖数量却为 '+IntToStr(PickNo)+ '!  请重新设置。 '); 
        Exit; 
      end;   Gauge.Progress:=0;//初始化进度条的位置为0  
     for I:=1 to PickNo do //在这儿开始抽足够数量的奖  begin 
        Gauge.Progress:=50*I Div PickNo; 
        j:=0; 
        randomize; 
        //现在开始抽奖,随机行号,即那个奖品,要么就是空奖了,哈
        RandomBaseLen:=Random(BaseLen)+1; //在这儿明白了,文本文件中的东西应该是奖品什么的东西,行数应该是奖品数量的意思
        while J <I do 
        begin 
          if inttostr(RandomBaseLen) < >Pick[J] then 
            J:=J+1 
          else 
          begin 
            Randomize; 
            RandomBaseLen:=Random(BaseLen)+1; 
            J:=0 
          end; 
        end; 
        Pick[I]:=IntToStr(RandomBaseLen);//这个大循环,还没搞清楚,下面的东西交给同志们吧,歇歇,哈 
      end;   AssignFile(BaseFile,TextEdit.Text); 
      Reset(BaseFile);AssignFile(BaseFile,TextEdit.Text); 
      Reset(BaseFile); 
      for J:=1 to BaseLen do 
      begin 
        Gauge.Progress:=50+50*J Div BaseLen; 
        Readln(BaseFile,BaseStr); 
        for I:=1 to PickNo do 
        begin 
        if IntToStr(J)=Pick[I] then 
          begin 
            if I <=StrToInt(SpinEdit1.Text) then 
            begin 
              PickStr[I]:=BaseStr; 
              break; 
            end; 
            if (I <=StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I >StrToInt(SpinEdit1.Text)) then 
            begin 
              PickStr[I]:=BaseStr; 
              break; 
            end; 
            if (I <=StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I >StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) then 
            begin 
              PickStr[I]:=BaseStr; 
              break; 
            end; 
            if (I <=StrToInt(SpinEdit4.Text)+StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) and (I >StrToInt(SpinEdit3.Text)+StrToInt(SpinEdit2.Text)+StrToInt(SpinEdit1.Text)) then 
            begin 
              PickStr[I]:=BaseStr; 
              break; 
            end; 
          end; 
        end; 
      end; 
      CloseFile(BaseFile); 
      

  2.   

    谢谢hys_427朋友
    还请大家多多帮忙啊