Solved

DLL with a form and result

Posted on 2006-06-19
9
170 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 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