Subclass to add a new object

Please discuss general Delphi programming topics here.

Subclass to add a new object

Postby Hankdog » January 24th, 2009, 8:29 pm

I am trying to subclass a TTntFindDialog, which is itself a subclass of TFindDialog. I would like to add a combo box to the dialog but am not having a lot of success. I need to specify a parent for the combo box (parent has to be the dialog) but I don't know how to do it. I either get "object has no parent" as design or run time, or I get a AV when I drop the component onto the form. I would appreciate some help on this. My code follows:

Code: Select all
unit TntFindDialog_Custom;

interface

uses
  Windows, SysUtils, Classes, TntDialogs, StdCtrls, TntStdCtrls, Graphics, Dialogs, Controls;

type
  TTntFindDialog_Custom = class(TTntFindDialog)
  private
    LanguagesCB: TTntComboBox;
    { Private declarations }
  protected
    { Protected declarations }
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { Public declarations }
  published
    { Published declarations }
  end;

procedure Register;

implementation

constructor TTntFindDialog_Custom.Create(AOwner: TComponent);
begin
{if AOwner is TWinControl then
  LanguagesCB := TTntComboBox.Create(AOwner)
else
  LanguagesCB := TTntComboBox.Create(nil);}
inherited Create(AOwner);
LanguagesCB := TTntComboBox.Create(Self);
with LanguagesCB do
  begin
  SetSubComponent(True);
  Name := 'cbLang';
  Parent := TWinControl(Self);
//  Parent := TWinControl(Self);
  Left := 387;
  Top := 225;
  Width := 49;
  Height := 23;
  Hint := 'Select a range for the search';
  Style := csDropDownList;
  Font.Charset := DEFAULT_CHARSET;
  Font.Color := clBlack;
  Font.Height := -11;
  Font.Name := 'Arial Unicode MS';
  Font.Style := [];
  ItemHeight := 15;
  ParentFont := False;
  TabOrder := 3;
  Items.Add('All');
  Items.Add('1');
  Items.Add('2');
  Items.Add('3');
  Items.Add('4');
  Items.Add('5');
  Items.Add('6');
  Items.Add('7');
  end;
end; //Create

destructor TTntFindDialog_Custom.Destroy;
begin
inherited Destroy;
end;

procedure Register;
begin
  RegisterComponents('Custom', [TTntFindDialog_Custom]);
end;

end.
Hankdog
Member
Member
 
Posts: 2
Joined: October 10th, 2006, 3:41 pm

Re: Subclass to add a new object

Postby Kambiz » January 24th, 2009, 10:07 pm

I am talking about TFindDialog because I don't have TNT controls.

The window is not created until Execute is calls. Therefore you have subclass Execute and create your control there. In this case, for releasing your control you should use CloseDialog. Another solution is sub-classing MessageHook and on WM_CREATE and WM_DESTROY messages, create your control.

But there is another big problem, TFindDialog keeps window handle as private and you do not a handle to set for parent of your control. You have to spy FindDialog to find class name of its window, and then at run-time look up for the handle of the window. Instead of Parent property, use ParentWindow property of your control.
Kambiz
User avatar
Kambiz
Administrator
Administrator
 
Posts: 2429
Joined: March 7th, 2003, 7:10 pm


Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 4 guests

cron