?
Solved

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

Posted on 2006-11-26
7
Medium Priority
?
219 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 2000 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
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!

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 1 hour left to enroll

770 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