Sending/Passing local variable from one procedure to another in Delphi 7? -
how can send/passing local variable in procedure procedure in delphi?
procedure tform1.button1click(sender: tobject); var a,b:integer; c: array [o..3] smallint; begin a:=1; b:=2; end;
i want send 1 or more local variable(a,b,c) has value procedure use them there like:
procedure tform1.button2click(sender: tobject); var d:integer; begin d:=a*b; end;
i want send 1 or more local variable(a,b,c) has value procedure use them there.
this shows misunderstanding lifetime of local variables. local variables have scope duration of function owns them. since 2 event handlers have disjoint lifetimes, local variables never in existence simultaneously.
so when "that has value", mistaken. local variables exist when button1click
executing not exist when button2click
executing.
you'd need variables members of class rather local variables. way variables' lifetimes span separate execution of event handlers.
type tform1 = class(tform) .... private a,b:integer; // etc. end; .... procedure tform1.button1click(sender: tobject); begin a:=1; b:=2; end; procedure tform1.button2click(sender: tobject); var d:integer; begin d:=a*b; end;
Comments
Post a Comment