Solved

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

Posted on 2006-11-26
7
216 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: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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 82
Delphi 2 69
Is anyone willing to have a look through this code and help debug? 25 84
How to build JSON File in Delphi 6 3 46
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

830 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