2012-01-03 13 views
-4

ラジオグループの4つのラジオボタンをグループ化しました。ファイルの作成、フォルダの作成、ラジオボタンの削除、コピーがありますが、コピーボタンに問題があります。Delphiのラジオボタン

これは大丈夫ですが、メッセージウィンドウ(ファイルがハードドライブにコピーされた場所を示す)が閉じていません。どうすればそれを閉じることができますか?または、ラジオボタンをリフレッシュする方法はありますか?

これは宿題の問題です。このコードはこのかなり陰惨なイベントハンドラの最後で

procedure TForm1.btnsubmitClick(Sender: TObject); 
    var 
    i,j,k,t,index,pred,delp,temp,temp2:integer; 
begin 
if rbtncreatefolder.checked = true then 
    begin 
    if (length(edit3.Text)>0) and (edit3.Text<>'..') then begin 
     if (VS>=3) then begin 
     if sush(true,nk1,edit3.Text) then begin 

     i:=tabld[nk1].nach; 
     while fat[i]<>1024 do i:=fat[i]; 
     fat[i]:=freep(i); 
     tabld[fat[i]].name:=edit3.Text; 
     tabld[fat[i]].format:=''; 
     tabld[fat[i]].tip:=true; 
     fat[fat[i]]:=1024; 
     k:=freep(fat[i]); 
     tabld[fat[i]].nach:=k; 
     tabld[k].name:='.'; 
     tabld[k].tip:=true; 
     tabld[k].nach:=fat[i]; 
     t:=freep(k); 
     fat[k]:=t; 
     tabld[t].name:='..'; 
     tabld[t].tip:=true; 
     tabld[t].nach:=nk1; 
     fat[t]:=1024; 
     tabld[fat[i]].razmer:=0; 
     tabld[i].razmer:=tabld[i].razmer+1; 
     reload; 
     end 
     end 
     else 
      showmessage('Not enough free memory!'); 
    end 
    else 
     showmessage('Incorrect data or absent!'); 
end 
else if rbtncreatefile.Checked = true then 
    begin 
    if (length(edit3.Text)>0) and (length(edit4.Text)>0)then begin 
     if strtoint(edit4.Text)<32*VS then begin 
     if sush(false,nk1,edit3.Text) then begin 

     i:=tabld[nk1].nach; 
     while fat[i]<>1024 do i:=fat[i]; 
     fat[i]:=freep(i); 
     tabld[fat[i]].name:=edit3.Text; 
     tabld[fat[i]].format:=copy(edit3.Text,length(edit3.Text)-4,3); 
     tabld[fat[i]].tip:=false; 
     tabld[fat[i]].razmer:=strtoint(edit4.Text); 
     if radiobutton1.Checked then 
      tabld[fat[i]].format:='txt' 
     else 
      tabld[fat[i]].format:='bin'; 
     tabld[fat[i]].nach:=freep(fat[i]); 
     k:=tabld[fat[i]].nach; 
     fat[fat[i]]:=1024; 
     for j:=1 to (tabld[fat[i]].razmer-9) div 32 do begin 
      fat[k]:=freep(k); 
      k:=fat[k]; 
     end; 
     fat[k]:=1024; 
     reload; 
     end 
     end 
     else 
      showmessage('Not enough free memory!'); 
    end 
    else 
     showmessage('You did not enter name and \ or File Size!'); 
end 
else if rbtndelete.checked = true then 
    begin 
if listbox1.ItemIndex>=0 then begin 
    if listbox1.Items.Strings[listbox1.ItemIndex]<>'dir>..' then begin 
    pred:=tabld[nk1].nach; 
    index:=tabld[nk1].nach; 
    for i:=0 to listbox1.ItemIndex do begin 
     index:=fat[index]; 
     if i>0 then 
      pred:=fat[pred]; 
    end; 
    delP:=index; 
    fat[pred]:=fat[index]; 
    if tabld[index].tip then begin 
    showmessage('directory "'+tabld[index].name+'" and all its subdirectories have been deleted!'); 
     rekur(tabld[delp].nach); 
     fat[delp]:=0; 
     fat[tabld[delp].nach]:=0; 
    end 
    else begin 
    showmessage('file "'+tabld[index].name+'.'+tabld[index].format+'" was removed!'); 
     i:=tabld[index].nach; 
     while fat[i]<>1024 do begin 
     j:=i; 
     i:=fat[i]; 
     fat[j]:=0; 
     end; 
     fat[i]:=0; 
     fat[index]:=0; 
     end; 
     reload; 
    end 
    else 
     showmessage('You can not delete this directory!'); 
end 
else 
    showmessage('You did not select the folder to delete!'); 
end 

else if rbtncopy.checked = true then 
    begin 
if listbox1.ItemIndex>=0 then begin 
    if listbox1.Items.Strings[listbox1.ItemIndex]<>'dir>..' then begin 
     index:=tabld[nk1].nach; 
     for i:=0 to listbox1.ItemIndex do 
      index:=fat[index]; 
     if tabld[index].tip then begin 
      showmessage('directory "'+tabld[index].name+'" and all its subdirectories are copied to the directory "'+edit2.text+'" !'); 
      temp:=nk1; 
      nk1:=nk2; 
      edit3.Text:=tabld[index].name; 
      btnsubmit.Click; 
      temp2:=tabld[nk2].nach; 
       while (fat[temp2]<>1024) and (tabld[temp2].name<>tabld[nk1].name) do temp2:=fat[temp2]; 
      rekurC(fat[tabld[index].nach],temp2); 
      nk1:=temp; 
     end 
     else begin 
      showmessage('file "'+tabld[index].name+'.'+tabld[index].format+'" was copied to directory "'+edit2.Text+'"!'); 
      temp:=nk1; 
      nk1:=nk2; 
      edit3.Text:=tabld[index].name; 
      edit4.Text:=inttostr(tabld[index].razmer); 
      btnsubmit.Click; 
      nk1:=temp; 
     end 
    end 
    else 
     showmessage('This directory may not be copied!'); 
end 
else 
    showmessage('You have not picked anything up to copy!'); 
      reload; 

end 

else 
showmessage('select an operator please'); 
end; 
+1

'sush'と' tabld'とは何ですか? 'tabld'はどのように埋められ、' freep'、 'fat'と' fat'がいっぱいです、 'reload'; 2つのヒントは間違いなくあなたの書式を改善する、私はあなたがこのコードで迷っているのではない、変数名として 'pred'を使わないで、' 'Pred''(http://docwiki.embarcadero .com/VCL/en/System.Pred)関数を使用します。 – TLama

+0

これはFAT32ファイルシステムで、宿題に割り当てられたメモリでシミュレートされていますか? –

+0

'rbtncreatefolder.checked = true'のような行を書く必要はありません。 'if rbtncreatefolder.checked'と書くだけで十分でしょう。私はこの構造体を使うつもりはない: 'case'ステートメントでradiogroup.itemindex値を使う。 –

答えて

10

権利である:ここで

は私のコードで、次に何が起こる

showmessage('file "'+tabld[index].name+'.'+tabld[index].format+ 
    '" was copied to directory "'+edit2.Text+'"!'); 
...//do stuff 
btnsubmit.Click; 

があるとすぐに、[OK]をクリックしてメッセージボックスでは、btnsubmit.Clickを呼び出したためイベントハンドラが再入力され、ルーチン全体が再び開始されます。メッセージボックスが表示され、OKを押すとbtnsubmit.Clickが再度呼び出されます。あなたが十分な忍耐を持っているなら、スタックオーバーフローエラーを得ることができるはずです!

+2

+1あなたの預言的能力のために、私はクリスタルボールを持って最後にこのコードを読むのに十分な忍耐がありません:) – TLama

+3

デビッドはEmbarcaderoに彼の "brain delphi compiler"を売るべきだと思います。 :) – RRUZ

+2

+1、ちょうど、「やっぱり大変なイベントハンドラ」これは残念ですが、それは昨年の「厄介なイベントハンドラ」の大会で優勝したでしょう。さて、ある開発者がそれを打ち負かす別の年です:)まあ、OK、おそらく再帰問題のポイント... –