Search code examples
delphi-7

mysq[i].caption into editbox.text on delphi 7


I keep getting the full alphabet with this program when I only want the letter. How do I get the specific letter?

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;

Solution

  • Assuming mySqMouseDown has been assigned to all TPanel OnMouseDown event, then the correct code is this one:

    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;