Recent

Author Topic: Change the value of other Unit.  (Read 4609 times)

T-bear

  • Full Member
  • ***
  • Posts: 160
Change the value of other Unit.
« on: April 09, 2011, 09:23:24 pm »
Hi,
How can i for example change the value of a variable in Unit1, in the code of Unit2?
Thanks!  :D

Dibo

  • Hero Member
  • *****
  • Posts: 1057
Re: Change the value of other Unit.
« Reply #1 on: April 09, 2011, 09:29:58 pm »
Add Unit1 to Unit2 "uses" section. But lookout for circular unit reference. If you use unit2 in unit1 too then you must add unit1 in implementation section in unit2 (add "uses" after implementation if it doesn't exists)

T-bear

  • Full Member
  • ***
  • Posts: 160
Re: Change the value of other Unit.
« Reply #2 on: April 09, 2011, 09:37:53 pm »
That was what i thought to, but it doesnt seem to work:
In Unit1 the string variable path is set:
Code: [Select]
Unit2.Path:='Kampagne\Tutorial.txt';
Then Form2 is shown, and in the OnShow event of Form2 the code is like this:
Code: [Select]
Form2.Caption:=Path;
But The Caption of Form2 does not change. What have i missed.

Thanks!  :D

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Change the value of other Unit.
« Reply #3 on: April 09, 2011, 10:00:57 pm »
If caption doesn't change, maybe your event (onShow?) is not executing?

When you do like this:
Code: [Select]
procedure TForm1.Button1Click(sender: TObject);
begin
  form2.caption:='test';
end;
That is exactly the same thing you are after, a reference to another unit. My guess is you are missing a small typo or something.

TurboRascal

  • Hero Member
  • *****
  • Posts: 672
  • "Good sysadmin. Bad programmer."™
Re: Change the value of other Unit.
« Reply #4 on: April 12, 2011, 03:08:09 am »
In Unit1 the string variable path is set:

Where exactly in the Unit1 the variable is set? Is it in an event handler?
Regards, ArNy the Turbo Rascal
-
"The secret is to give them what they need, not what they want." - Scotty, STTNG:Relics

 

TinyPortal © 2005-2018