Charles van den akker III
Posts: 4
Joined: 2006-02-28
|
Hello...
I am using, i would think a rather complex way of using forms and am concerned that there are memory issues...
TAddinModule
...
uses DelphiFRM
...
Var
MyForm : TDelphiFRM;
...
Then on InitializeAddin
MyFormVar := TMyForm.Create(nil);
Is this the best way? |
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Charles,
I would recommend you using the following code.
uses DelphiFRM;
procedure TAddInModule.adxCommandBar1Controls0Click(Sender: TObject);
begin
MyFormVar := TMyForm.Create(nil);
try
MyFormVar.ShowModal;
finally
FreeAndNil(MyFormVar);
end;
end
|
|
Wim W.A. ten Brink
Workshop Alex
Posts: 30
Joined: 2005-11-23
|
I agree with Dmitry, with a few notes:
procedure TAddInModule.adxCommandBar1Controls0Click(Sender: TObject);
var
MyForm : TMyForm;
begin
MyForm := TMyForm.Create(Self);
try
MyForm.ShowModal;
finally MyFormVar.Free;
end;
end;
With Delphi forms, I tend to remove the global form variables, especially when I create new forms of those forms by code. (They are only needed when you auto-create those forms from the project options, which you can't do with add-ins and other DLL's.)
And personally, I think it's a bit cleaner and more safe to use local variables for forms. Cleaner because it saves a few bytes in your global data segments. More safe because there's less risk of accidently altering the value of such variables with another value.
The second note is that I use Create(Self) instead of Create(nil) simply because the TAddInModule class is inherited from TComponent and knows how to free any child components (and a form is a component too) that are linked to it. Thus, even if the Finally doesn't free the form, the add-in still will free it when destroyed.
And a third note: in my add-in I use several forms that are non-modal. I create them on the OnInitialize event and free them on the OnFinalize event. While Outlook is running I just show and hide these forms as need be. This too is an effective way to handle Delphi forms.With kind regards,
\/\//\ Workshop Alex |
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Wim,
Thank you for your comments.
|
|
Roger Tobler
Posts: 1
Joined: 2006-05-02
|
It work's fine for opening a form, but how do I close it without creating errors?
isn't it possible to do a form.hide or a form.close?
thanks |
|
Dmitry Kostochko
Add-in Express team
Posts: 2887
Joined: 2004-04-05
|
Hi Roger,
Why not? You definitely can do a Form.Close, and you need to make some changes in the code from the post above to do a Form.Hide.
|
|