Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2006-11-26
7
Medium Priority
?
221 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Independent Software Vendors: 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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

609 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