Solved

DLL with a form and result

Posted on 2006-06-19
9
175 Views
Last Modified: 2010-04-05
I need a skeleton DLL that shows a form with a Memo, checkbox and two buttons.
When the form is closed, I need the DLL to return the value of the checkbox
(0 for unchecked, 1 for checked). This is for a EULA dialog with a do not show again checkbox.

I'd like to load the DLL and then call a function like ShowEULA and then have the result of the
checkbox returned, If the user clicks button2, I'd like a result of 2 returned.
0
Comment
Question by:EddieShipman
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
9 Comments
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16935154
Hi,

The dll will look like the following.

library EULA;

uses
  SysUtils,
  Classes,
  Unit1 in 'Unit1.pas' {Form1}; // This is your form what contains memo, checkbox, button etc.

{$R *.res}

function ShowEULA : boolean;
begin
  with TForm1.Create(nil) do
  begin
    try
      ShowModal;
      Result := CheckBox1.Checked;
    finally
      Free;
    end;
  end;
end;

exports
  ShowEULA;

begin
end.
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 500 total points
ID: 16935216
Sorry, you need the result to be 0, 1 and 2. So, I expect that Button1 will set the ModalResult to mrOk and Button2 will brCancel.

function ShowEULA : Integer;
begin
  with TForm1.Create(nil) do
  begin
    try
      if ShowModal = mrOk then
      begin
        if CheckBox1.Checked then Result := 1 else Result := 0;
      end
      else // for 2nd button
         Result := 2;
    finally
      Free;
    end;
  end;
end;
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935235
I was going to accept that as answer but you only return one value.
I need a 0 if unchecked, 1 if checked, and 2 if button2 was clicked.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 26

Author Comment

by:EddieShipman
ID: 16935237
oh, didn't see your second post...
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935255
Now do I use it like this:

LoadLibrary(EULA)
case ShowEULA of
0: do this
1: do this
2: do this
end;
ReleaseLibrary(EULA);

0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935258
I mean FreeLIbrary(EULA);
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935327
Ok, got it:

type
   TEULAFunc = function: integer; stdcall;

procedure TForm1.Button1Click(Sender: TObject);
var
  hMod: HMODULE;
  FShowEULAFunc: TEULAFunc;
begin
  hMod := LoadLibrary('C:\Projects\EULA.dll');
  try
    @FShowEULAFunc:=GetProcAddress(hMod, 'ShowEULA');
    case FShowEULAFunc of
    0: ShowMessage('0');
    1: ShowMessage('1');
    2: ShowMessage('2');
    end;
  finally
    FreeLibrary(hMod);
  end;
end;
0
 
LVL 10

Expert Comment

by:atul_parmar
ID: 16935350
Yep.

I am moving mate, see you next day.
0
 
LVL 26

Author Comment

by:EddieShipman
ID: 16935844
Thanks for the help.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

695 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question