首页 > 解决方案 > mysq[i].caption 到 delphi 7 上的 editbox.text

问题描述

当我只想要字母时,我会一直使用这个程序获得完整的字母表。我如何获得具体的信件?

var 
  Form1: TForm1;
  mysq : array[1..26] of TPanel;

implementation

…

procedure TForm1.mySqMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  i, a: integer; 
begin  
  a := StrToInt(lab_leftn.Caption);
  
  lab_leftn.Caption := IntToStr(a - 1);

  if lab_leftn.Caption = IntToStr(0) then    
  begin     
    ShowMessage('You have lost');     
    lab_leftn.Caption := IntToStr(0);
  end;

  for i := 1 to 26 do
    ed_guessed.Text := ed_guessed.Text + mysq[i].Caption;
end;

标签: delphi-7

解决方案


假设 mySqMouseDown 已分配给所有 TPanel OnMouseDown 事件,那么正确的代码是这个:

procedure TForm1.mySqMouseDown(
    Sender : TObject; 
    Button : TMouseButton;
    Shift  : TShiftState; 
    X, Y   : Integer);
var
  i, a: integer; 
begin  
  a := StrToInt(lab_leftn.Caption);
  lab_leftn.Caption := IntToStr(a - 1);
  if lab_leftn.Caption = IntToStr(0) then begin     
    ShowMessage('You have lost');     
    lab_leftn.Caption := IntToStr(0);
  end;

  ed_guessed.Text := (Sender as TPanel).Caption;
end;

推荐阅读