Link to home
Start Free TrialLog in
Avatar of boardtc
boardtcFlag for Ireland

asked on

derived class creat not called

I have a form class that is derived from a form template. When I create the derived class the OnCreate for the derived class is not called and the form template appears. Does anyone have an idea what am may be doing wrong?

Thanks, Tom.
Avatar of viktornet
viktornet
Flag of United States of America image

Some code will help??? What is your code in the OnCreate() of the form.....

Regards,
Viktor Ivanov
Avatar of boardtc

ASKER

Viktor,

Here's some code snippets:

   with TfrmSchedGridConfig.Create(Self) do
      try
         if not (ShowModal = mrCancel) then begin
            ...
         end;
      finally
         Free;
      end;

  TfrmSchedGridConfig = class(TfrmRepDDLst)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure btnOkClick(Sender: TObject);
  private
    { Private declarations }
   ...
  public
    { Public declarations }
  end;
.

procedure TfrmSchedGridConfig.FormCreate(Sender: TObject);
begin
   inherited; // never goes in here
   ...
end;

Thanks, Tom.


Why dont youtry without inherited because you never override the OnCreate() of that form...Try wihout having the inherited method and enter some other code for example to show you a message so you can see that it's working...

//Viktor
Avatar of boardtc

ASKER

Well like I said it never goes in there (regardless of whether inheritd is commented out or not). Tom.
Why don't you send the whole coed on th E-E

Oh, and tell me where does this code come from???

with TfrmSchedGridConfig.Create(Self) do
           try
              if not (ShowModal = mrCancel) then begin
                 ...
              end;
           finally
              Free;
           end;

vik
Avatar of boardtc

ASKER

Vik,

Thanks for your help. I just found what it was, the form create had somehow got disconnected in the object inspector...

Tom.
Avatar of KE
KE

Add this to your public declaration of TfrmSchedGridConfig

public
  Constructor Create( AOwner: TObject ); override;

In your implementation part write the Constructor as follows

Constructor TfrmSchedGridConfig( AOwner: TObject );
begin
  Inherited Create( AOwner );
  FormCreate( self );
end;

I just created a unit to try this out......and here is the code for the whole unit and it works perfectly..........
-------------------------
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls;
type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
      ShowMessage('Hello');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
      with TForm1.Create(self) do
    try
          Randomize;
        Left := Random(Screen.Width);
        Top := Random(Screen.Height);
        Caption := 'Hello World';
          ShowModal;
    finally
          Free;
    end;
end;

end.
--------------
Regards,
Viktor Ivanov
as Tom said he has fixed the problem.....

//Viktor Ivanov
Avatar of boardtc

ASKER

Vic, thanks for all the work, answer so I can grade, Tom.
ASKER CERTIFIED SOLUTION
Avatar of viktornet
viktornet
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial