Using VCL Forms in an Outlook Plug-In

Add-in Express™ Support Service
That's what is more important than anything else

Using VCL Forms in an Outlook Plug-In
Using VCL Forms in an Outlook Plug-In 
William Vermaak




Posts: 8
Joined: 2017-01-11
Hey guys,

Quick question. I'm writing my first Plug-In using Delphi. I would like to find out is it possible to show a normal VCL Form on a button event for example? I've tried it using the old fashioned Form2.Visible := TRUE way to give it a bash and I get an exception in Outlook as soon as I press the button.

I need a login dialog to display when the button is clicked.

Sincerely,
William
Posted 11 Jan, 2017 07:16:39 Top
William Vermaak




Posts: 8
Joined: 2017-01-11
I have tried the proposed solutions posted below, but to no avail.
https://www.add-in-express.com/forum/read.php?FID=1&TID=1319

The exact error is:
OutlookCompTest error: the add-in has fired an exception.
Access violation at address 275BF863 in module 'Outlook_Comp_Tester.dll'.
Read of address 000003BC
Posted 11 Jan, 2017 07:48:20 Top
William Vermaak




Posts: 8
Joined: 2017-01-11
OK, got this working. It shows the form, but when you hide it it doesn't unhide again.

Any ideas? I think I may need to destroy the form or something.

For interest sake, Here's what I did:

1) Add the Forms Unit
2) Add a VCL Form to my Project
3) Add below to a Ribbon Button

procedure TAddInModule.adxRibbonTab1Controls0Controls1Click(Sender: TObject;
  const RibbonControl: IRibbonControl);
begin
    Application.Initialize;
    Application.CreateForm(TLoginForm, LoginForm);
    Application.Title := 'Login';
    Application.Run;
    LoginForm.Visible := TRUE;
end;
Posted 11 Jan, 2017 08:17:16 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello William,

Quick and dirty:

...
implementation

{$R *.dfm}

var frm: TForm1;

procedure TAddInModule.adxRibbonTab1Controls0Controls1Click(
  Sender: TObject; const RibbonControl: IRibbonControl);
begin
  frm := TForm1.Create(self);
  frm.Show;
end;

procedure TAddInModule.adxRibbonTab1Controls0Controls2Click(
  Sender: TObject; const RibbonControl: IRibbonControl);
begin
  if Assigned(frm) then frm.Free;
end;



Andrei Smolin
Add-in Express Team Leader
Posted 11 Jan, 2017 09:31:37 Top
William Vermaak




Posts: 8
Joined: 2017-01-11
Hi Andrei,

Thankyou so much for the help. Any idea how I close the form from the open form itself? As far as I'm aware I will need to call the free from the main unit. Sheesh, I feel like a newbie :)

Sincerely,
William Vermaak
Posted 12 Jan, 2017 03:42:15 Top
William Vermaak




Posts: 8
Joined: 2017-01-11
Nevermind. Just call FreeAndNil(Self) and it will close the form :)
Posted 12 Jan, 2017 05:35:42 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
No problem ))


Andrei Smolin
Add-in Express Team Leader
Posted 12 Jan, 2017 06:02:11 Top