Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scope

Status
Not open for further replies.

lennynuts

Programmer
Oct 12, 2006
9
GB
Just learning Delphi, I have a button and a text box on a form,
in the button click procedure this works ok,
edit1.Text := '123456';
but i want to put it in a procedure to call from other places, but
procedure tempit();
begin
Form1.edit1.Text := '123456';
end;
in the same unit doesn't work.
Why is this, and why do I need the form1. when it's in the same unit,

Thanks,
Len
 
Hi,

you need the form1 reference because your tempit procedure isn't part of the TForm1 object. whereas the Button1Click procedure is a member of the TForm1 object


In this code sample, the nonmember procedure is not defined in the TForm1 object, so this is a regular procedure.
The member procedure is part of the TForm1 object (in the private section), this procedure is called an object Method

Code:
unit Unit1;

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure Nonmember;
begin
  form1.edit1.Text:='nonmember';
end;

procedure TForm1.Member;
begin
 Edit1.Text:='member';
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
// do something
end;

end.

-----------------------------------------------------
What You See Is What You Get
Never underestimate tha powah of tha google!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top