Quote
In article <3B572E23.2476D...@azdogs.com>, Jim Andrews <j...@azdogs.com> writes:
>I pass these forms some initialization values to their public variables
>after I create them. I want to avoid using global variables for these
>values and don't like "cross-uses" statements where the called form also
>"uses" the form that calls it.
>If I use OnActivate to initialize the form it gets re-initialized when
>the form becomes active again after the calling another modal form.
If the "modal" form is system modal then it would not bere-activated, but if it
is only application modal then it could be.
Quote
>Is there an easy way to have something only run once other than having a
>boolean variable that is set during OnActivate that disables this
>function when it is run again or should I just do it as shown below?
>private
> ActivateDone : boolean;
>Procedure tForm1.FormCreate;
>begin
> ActivateDone := false; // Initializes to false during create but you
>never know in the future.
As I understand it, all object data is set to 0, 0.0000, nil, '' (or whatever
zero is) when created.
If by a "global" variable (which you don't want to use) you mean ...
interface
var <------- here
implementation
var
... then you could set a class variable which is ...
interface
var
implementation
var <------- here
... and use a write only form property, which is set using a property method to
also maintain the class variable. The class .Create sets the initial private
property value from the class variable ...
private
{ Private declarations }
FMyInt : integer;
procedure SetMyInt(AValue : integer);
public
property MyInt : integer write SetMyInt;
end;
var
Form2: TForm2;
implementation
{$R *.DFM}
var
MyIntInitial : integer;
procedure TForm2.FormCreate(Sender: TObject);
begin
FMyInt := MyIntInitial; // FMyInt is used in other class methods
end;
procedure TForm2.SetMyInt(AValue : integer);
begin
MyIntInitial := AValue; // sets class variable
if FMyInt <> AValue then // usual other stuff
FMyInt := AValue;
end;
Then to set the class variable from other forms ...
with TForm2.Create(self) do begin
MyInt := 29;
Free;
end;
... or set it the first time that form is used ...
Form2 := TForm2.Create(Self);
Form2.MyInt := 29;
Form2.ShowModal;
Form2.Free;
... and later uses would use the class variable value in the .Create method of
the class ...
Form2 := TForm2.Create(Self);
Form2.ShowModal;
Form2.Free;
You could also use a record to hold all your settings to reduce coding;
I think its a bit messy - but it does what you want <g>.
Alan Lloyd
alangll...@aol.com