Solved

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

Posted on 2006-11-26
7
218 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
[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
  • 4
  • 2
7 Comments
 
LVL 28

Expert Comment

by:2266180
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
Industry Leaders: 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 28

Expert Comment

by:2266180
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

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

726 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