Board index » delphi » Help with this "simple" problem

Help with this "simple" problem

Quote
Stephen L. Legge wrote:

> In UNIT1 in the TYPE section under PUBLIC I have declared A : INTEGER;

> When I call FORM2 (which uses UNIT2) I try and increment A by 1,
> ie. Form1.A := Form1.A +1;
> or TForm1.A := TForm1.A +1;
> or simply A := A +1;

> But nothing seems to work.  What am I doing wrong?
> You say "nothing seems to work" but, didn't say what it actually did.

ie: compile error?  If you are trying to increment "A" from a procedure
in unit2, then your first example should work if you put Unit1 in the
uses of unit2.

Gary

 

Re:Help with this "simple" problem


In UNIT1 in the TYPE section under PUBLIC I have declared A : INTEGER;

When I call FORM2 (which uses UNIT2) I try and increment A by 1,
ie. Form1.A := Form1.A +1;
or TForm1.A := TForm1.A +1;
or simply A := A +1;

But nothing seems to work.  What am I doing wrong?

Thanks.

Stephen LEAFS Legge
SLE...@cs.mun.ca - www.cs.mun.ca/~slegge
St. John's, Newfoundland

Re:Help with this "simple" problem


Quote
>   sle...@cs.mun.ca (Stephen L. Legge) writes:
>  In UNIT1 in the TYPE section under PUBLIC I have declared A : INTEGER;

>  When I call FORM2 (which uses UNIT2) I try and increment A by 1,
>  ie. Form1.A := Form1.A +1;

This is the right way to do it.

In Unit2 I coded this:

type
  TForm2 = class(TForm)
  private
    { Private declarations }
  public
    i: integer;
    { Public declarations }
  end;

var
  Form2: TForm2;

In Unit1, which uses Unit2, this code works just fine:

procedure TForm1.Button1Click(Sender: TObject);
begin
  Form2.i := 1;
  ShowMessage(IntToStr(Form2.i));
end;

Re:Help with this "simple" problem


Quote
On Sat, 27 Jul 1996, Stephen L. Legge wrote:
> In UNIT1 in the TYPE section under PUBLIC I have declared A : INTEGER;

> When I call FORM2 (which uses UNIT2) I try and increment A by 1,
> ie. Form1.A := Form1.A +1;
> or TForm1.A := TForm1.A +1;
> or simply A := A +1;

> But nothing seems to work.  What am I doing wrong?

This may be wrong, but one place you may want to look is in the Unit2 Uses
declarations.  In order for Form1 to be used in Unit2, I believe that you
must declare Form1's unit in Unit2's Uses.  This may be incorrect, but
give it a try and see if it doesn't clear things up...

Hope this is helpful.

Dov

//////////////////////////////////////////////////////////////////////////
// J Dov Kaplan, programmer, CMI, student, University of Arizona, Csc   //
// home: (520) 624-9335    work: (520) 621-4761                         //
// kap...@lectura.cs.arizona.edu                                        //
// j...@aol.com                                                         //
//////////////////////////////////////////////////////////////////////////

Re:Help with this "simple" problem


Quote
In article <4te2nr$...@coranto.ucs.mun.ca> Stephen L. Legge wrote:
>When I call FORM2 (which uses UNIT2) I try and increment A by 1,
>ie. Form1.A := Form1.A +1;
>or TForm1.A := TForm1.A +1;
>or simply A := A +1;

  This seems ok to me and all the posts make sense.  So, are you sure it's
not updating?  Maybe it is but your Form1 is resetting it (i.e. in an
OnActivate or something)?
hth,
=scott

Other Threads