Visit our Sponsor   Visit our Sponsor
delphi3000.com - the free delphi knowledge platform
delphi3000.com - the free delphi knowledge platform
500 Users Online NOW
Have a look at your member-status

connecting people's knowledge


  - Recent ArticlesRSS feed for Recent Articles on delphi3000.com
  - List of All Articles
  - Top Viewed Articles
  - Articles (+Attachem.)
  - Articles Of Interest
  - Categories
  - Top Uploader
  - Search
  - Index

  - My Home
  - Submit an Article
  - My Articles
  - My Personal Data
  - My Bookmarks
  - Activities
  - Login/Logout

  - Sign Up
  - Why Sign Up
  - Newsletter

  - Press
  - Advertise

  - Contact
  - Feedback





Community
Borland
ClubeDelphi
Dr. Bob
UK-BUG
Delphi Meetings
Planeta Delphi



Loremo - the 1.5 liter car coming in 2009




Startblatt.de






Share this article with friendsShare this article with friends
Rate this articleRate this article - to keep the quality of delphi3000.com !
Comment this article or read through previous comments (6)


A lot of DLLs with forms, Load dynamically into a PageControl of a Main-FormGo to manfred süsens's websiteComponent available for this articleFormat this article printer-friendly!Bookmark function is only available for registered users!
How to load DLLs with forms to main Form
Product:
Delphi 4.x (or higher)
Category:
Win API
Skill Level:
Scoring:
Last Update:
04/26/2004
Search Keys:
delphi delphi3000 article borland vcl code-snippet DLL dynamically Form TabSheet
Times Scored:
4
Visits:
4621
Uploader: manfred süsens
Company: DÜRR Systems GmbH
Reference: N/A
Component Download: http://www.delphi3000.com/article/3656/3656.zip
 
Question/Problem/Abstract:
How to put DLL-Forms as Parent to a MainForm-PageControl-TabSheet?
Answer:



I know, there are a lot of samples from DLLs, but I don't found any one describing how to load DLLs with Forms into a Main form with a PageControl. Each DLL opens an own TTabSheet! Isn't it nice to see how it works?

====The DLL No. 1: =====(make so much you want like this)=========

unit uDLL;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TDLLForm = class(TForm)
    Label1: TLabel;
    Edit1: TEdit;
    ComboBox1: TComboBox;
    ListBox1: TListBox;
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;
  function Initialisation:HWND; stdcall; forward;
  function CloseDLL:Boolean; stdcall; forward;
var
  DLLForm: TDLLForm;
implementation
{$R *.DFM}
function Initialisation:HWND;
begin
  DLLForm:=TDLLForm.Create(nil);
  DLLForm.Caption:='TestDLL';
  result:=DLLForm.Handle;
end;
function CloseDLL:Boolean;
begin
  DLLForm.Release;
  result:=true;
end;
end.
===========The EXE ========================================

unit uMain;
interface
uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ComCtrls, StdCtrls, ExtCtrls;
type
  TInitialisation = function:HWND;
  TCloseDLL=function:Boolean;
  TTab = class(TTabSheet)
  private
    CloseDLL:TCloseDLL;
    LibDLL:THandle;
    WinHandle:HWND;
  end;
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    Panel1: TPanel;
    BtnSearchDLL: TButton;
    BtnClose: TButton;
    procedure BtnSearchDLLClick(Sender: TObject);
    procedure BtnCloseClick(Sender: TObject);
  private
    procedure adviceDLL(Name:String);
  end;
var
  Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.adviceDLL(Name:String);
var
  hndDLLHandle: THandle;
  Initialisation:TInitialisation;
  CloseDLL:TCloseDLL;
  Tab:TTab;
  WinHndl:HWND;
  WinName: Array [0..255] of char;
begin
  try
    // load dll in dinamic type(mode)
    hndDLLHandle := loadLibrary(PChar(Name));
    if hndDLLHandle <> 0 then begin
      // get function address
      @Initialisation:=getProcAddress(hndDLLHandle,'Initialisation');
      @CloseDLL:=getProcAddress(hndDLLHandle,'CloseDLL');
      // if function address exists
      if (addr(Initialisation)<>nil) AND (addr(CloseDLL)<>nil) then begin
        Tab:=TTab.Create(nil);
        Tab.PageControl:=PageControl1;
        WinHndl:=Initialisation;
        Windows.SetParent(WinHndl,Tab.handle);
        windows.ShowWindow(WinHndl,SW_SHOWMAXIMIZED);
        GetWindowText(WinHndl,WinName,255);
        Tab.Caption:=WinName;
        Tab.CloseDLL:=CloseDLL;
        Tab.LibDLL:=hndDLLHandle;
        Tab.WinHandle:=WinHndl;
      end;
    end;
  except
    on E:Exception do ShowMessage(E.Message);
  end;
end;
procedure TForm1.BtnSearchDLLClick(Sender: TObject);
var
  sr: TSearchRec;
begin
  if FindFirst('Test*.DLL',faAnyFile,sr) = 0 then begin
    adviceDLL(sr.Name);
    while FindNext(sr) = 0 do adviceDLL(sr.Name);
    FindClose(sr);
  end;
end;
procedure TForm1.BtnCloseClick(Sender: TObject);
var
  Tab:TTab;
  CloseDLL:TCloseDLL;
begin
  while PageControl1.PageCount<>0 do begin
    Tab:=TTab(PageControl1.Pages[0]);
    CloseDLL:=Tab.CloseDLL;
    Tab.PageControl:=nil;
    Tab.Free;
    CloseDLL;
  end;
end;
end.





Please rate this article!
Skill level:
BeginnerExpert

Useful:
No!Very!

Overall rating:
PoorExcellent



Comments to this article
Write a new comment
Load DLL
    Tan Nguyen (Oct 21 2003 2:37AM)

Thank you very much for your help... I got your demo.
I don't know whether I miss describe it for you or what but the way you load the DLL with form is work perfectly.. However, if you run the demo you sent to me you will see is if you use the tabkey to move from one control to another control you will see that the cursor does not move out to the button at the bottom of the screen(Seach DLL and CLose DLL).
As The application I am working on, the user does not use the mouse to move from one control to another. it must be all keyboard driven...
Hope you can help me out..
Thanks again.

Respond

RE: Load DLL
manfred süsens (Oct 29 2003 6:27PM)

I'm very sorry. It is tested on Win2k and works in all conditions.
Respond

Load DLL
    Tan Nguyen (Oct 20 2003 2:55AM)

Now I got all the control being displayed on the screen. However, when a control in dll got the focus then I switch to another application then switch back to the Dll, the focus being lost and regardless howmany tab key i press, the focus does not seem to appear, Please help.

thanks
Respond

RE: Load DLL
manfred süsens (Oct 20 2003 5:26PM)

I don't know what you've done. Send you a DEMO.
Respond

Rep
    Tan Nguyen (Sep 22 2003 7:55AM)

This souce does not work if you add a tedit component on the form, the run the client, the edit does not visible on the form.

Respond

RE: Rep
manfred süsens (Sep 22 2003 8:20PM)

Oh,Yes, I'm so sorry... I forget to tell you the trick: You have to set the DLL Form "Visible:=true".
Respond














 
Sign up to consume product discounts for Bronze memberships !

read more


  Visit our Sponsor

 

  Community Ad of
R. Lefter
 
   














 







     
  Copyright © 2000 - 2007 delphi3000.com - All rights reserved. Terms of use. || Privacy
delphi3000.com is a service by bluestep.com IT-Services GmbH (Vienna)