Solved

Why do speedbuttons appear and regular buttons not (both stored into a dll)?

Posted on 2006-11-26
7
212 Views
Last Modified: 2010-04-05
Hi my friends!

When loading a form onto the pagecontrol of my main program, I manage to let it display the speedbuttons which I put onto the form in the dll.
The buttons however, don't appear at all. Also any edits I add to that form in the dll, do not appear. Same goes for checboxes.

Why does it show speedbuttons and not buttons or checkboxes?

Kind regards,

Peter

Ps I'm aiming at a plugin interface. I want to be able to only have to modify the external form (the dll) and thus being able to 'change' the options of my main program. If you need more info please ask!
0
Comment
Question by:PeterdeB
  • 4
  • 2
7 Comments
 
LVL 28

Expert Comment

by:ciuly
ID: 18014896
well, for starters, speedbuttons are the only components that you mentioned which do not have a handle.
so my question is: how are you creating the form? is it saved as a resource? if so, are all resources includes (buttons.res, etc) or just the form one?
can you throw in a small demo? a basic dll with form and how you instantiate the form from dll.
0
 

Author Comment

by:PeterdeB
ID: 18014949
Hey ciuly!

Sure I can > here is the code I use (copy and paste work from another topic out here on EE with similar issue)

The programs main unit

//
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;
  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 dynamic 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(PageControl1);
        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;
      end;
    end;
  except
    on E:Exception do ShowMessage(E.Message);
  end;
end;
procedure TForm1.BtnSearchDLLClick(Sender: TObject);
var
  sr: TSearchRec;
begin
  if FindFirst('WINNTDLL.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
  n:Integer;
begin
  while PageControl1.PageCount<>0 do begin
    TTab(PageControl1.Pages[0]).CloseDLL;
    freeLibrary(TTab(PageControl1.Pages[0]).LibDLL);
    TTab(PageControl1.Pages[0]).Free;
  end;
end;
end.

//
The DLL
//
library winntDLL;
uses
  uDLL in 'uDLL.pas' {DLLFORM};

exports
  Initialisation name 'Initialisation',
  CloseDLL name 'CloseDLL';
begin
end.

The DLLs main unit

//
unit uDLL;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,
  Grids, Buttons;

type
  TDLLForm = class(TForm)
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    btnTest: TButton;
    Edit1: TEdit;
    SpeedButton2: TSpeedButton;
    CheckBox1: TCheckBox;
    SpeedButton3: TSpeedButton;
    procedure btnTestClick(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;
  function Initialisation:HWND; stdcall; forward;
  function CloseDLL:Boolean; stdcall; forward;
var
  DLLForm: TDLLForm;

implementation

{$R *.dfm}
function Initialisation:HWND;
begin
  DLLForm:=TDLLForm.Create(application);
  DLLForm.Caption:='TestNewDLL with button ';
  result:=DLLForm.Handle;
end;
function CloseDLL:Boolean;
begin
  DLLForm.Release;
  result:=true;
end;

procedure TDLLForm.btnTestClick(Sender: TObject);
begin
ShowMessage('Hello from Button1');
end;

procedure TDLLForm.SpeedButton1Click(Sender: TObject);
begin
showmessage('Hello from speedbutton1');
end;

end.


Kind regards,

Peter

Ps the handle thingie....must be the cause....any other approaches to achieve my goal are welcome btw...
0
 
LVL 4

Accepted Solution

by:
Meldrachaun earned 500 total points
ID: 18015014
I just wrote a sample app that works.  Compare with this to see what's different.  In the DLL:

type
  TForm4 = class(TForm)
    Button1: TButton;
    Edit1: TEdit;
    BitBtn1: TBitBtn;
    SpeedButton1: TSpeedButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

procedure Attach(tab: TTabSheet);

exports Attach;

implementation

{$R *.dfm}

procedure Attach(tab: TTabSheet);
var
  Form4: TForm4;

begin
  Form4 := TForm4.Create(tab.PageControl.Owner);
  Form4.ParentWindow := tab.Handle;
  Form4.Left := 0;
  Form4.Top := 0;
  Form4.Align := alClient;
  Form4.TabStop := TRUE;
  Form4.Show;
end;

procedure TForm4.Button1Click(Sender: TObject);
begin
  ShowMessage('boom');
end;

end.


The main program looks like this:


type
  TForm2 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    Panel1: TPanel;
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure Attach(tab: TTabSheet); external 'Project4.dll';

procedure TForm2.Button1Click(Sender: TObject);
begin
  Attach(PageControl1.ActivePage);
end;
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 28

Expert Comment

by:ciuly
ID: 18015063
I added in
function Initialisation:HWND;
the line
  assert(DLLForm.btnTest.HandleAllocated);
and it gave an error. so indeed the handles are not created. never encountered this so I'll have to dig a little
0
 

Author Comment

by:PeterdeB
ID: 18015138
Meldrachaun > could you upload that sample project of yours? I can't get it to compile, it keeps nagging about the 'undeclared identifier Attach'.

Kind regards,

Peter
0
 

Author Comment

by:PeterdeB
ID: 18015156
Got it already! Just a sec and I'll be back! ;-)

Kind regards,

Peter
0
 

Author Comment

by:PeterdeB
ID: 18015175
Meldrachaun thanks! Ciuly > thanks as well....you mention the assert thingie...its for debugging purposes then I suppose?

Kind regards,

Peter

Thanks for all the efforts you put into helping me out!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video discusses moving either the default database or any database to a new volume.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now