Page 1 of 1

[Delphi] Changing a label caption with a button

Posted: Sat Sep 05, 2009 10:15 am
by Boredness
Today, I'm gonna teach you how to change a label caption with a click of a button

1)Run Delphi
2)Put a label and a button to your form. (They're both under "Standerd" tab)
3)Change the label caption to "hello" (You may change to anything you want actually) at the Object Inspector.
4)Double click on the button and you should see the code.

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin

end;

end.
5)Under

Code: Select all

procedure TForm1.Button1Click(Sender: TObject);
begin
6)Compile you project by pressing F9.
7)Then, the exe should pop up, Click the button and then the 'hello' will become 'bye'.

This should be your final code

Code: Select all

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Label1: TLabel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
label1.Caption := 'Bye'
end;

end.

Re: [Delphi] Changing a label caption with a button

Posted: Sun Sep 06, 2009 7:31 pm
by bluefirzen
Thanks bro {: .
btw online msn soon.
i got some questions i wish to ask about this O_O LOL

Re: [Delphi] Changing a label caption with a button

Posted: Tue Sep 08, 2009 10:59 pm
by Boredness
bluefirzen wrote:Thanks bro {: .
btw online msn soon.
i got some questions i wish to ask about this O_O LOL
Post your questions here, i'm quite busy today