Topic: Propagating variables

Hello Dmitry and all MVDB users;


THIS QUESTION IS NOT URGENT, it's just my curiosity and maybe a little convenience of use that make me ask smile


In php, as long as a session is active, there is an easy way to keep already used variables and there values for reusing them.


I noticed that, as soon a an "end;" as been set for a procedure, the variables used in these procedure are lost and must be re-declared and re-calculated for use in the next procedure if needed.


Is there a way to keep those variables active and re-usable all along the code ? (global variables maybe ?)


Again, this is not an urgent question.


I wish you all a good day


Cheers


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Propagating variables

Yes, you can use global variables


example:

var
  i: integer;

procedure Form1_Button1_OnClick (Sender: string; var Cancel: boolean);
begin
    i := i + 1;
    ShowMessage(i);
end;
Dmitry.

Re: Propagating variables

I see you declare the variable before the procedure, and not between procedure and begin.


I suppose this means that the variable i will be reusable for other procedure after it as been declared but what about the result ?


Can I do something like :


var
DateTimeTot1 : TDateTime;
DateTimeTot2 : TDateTime;
diff, day, hour, minute : Integer;

DateTimeTot1 := Trunc(Form1.date_begin.DateTime) +  Frac(Form1.time_begin.DateTime);
DateTimeTot2 := Trunc(Form1.date_end.DateTime) +  Frac(Form1.time_end.DateTime);
diff:=  SecondsBetween(DateTimeTot1,DateTimeTot2);

Procedure
begin ...

I mean not only declaring variables but assigning values as well; that will be reused for different calculation in different procedures after that ?


Mathias

I'm a very good housekeeper !
Each time I get a divorce, I keep the house

Zaza Gabor

Re: Propagating variables

Yes, you can use the variables for other procedures.

To assign values, you should use procedures (also events), you can't assign values without procedure, like in your example.
Unfortunately I do not understand exactly what you do not understand )

Dmitry.