boardtc
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.
Thanks, Tom.
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.FormCr eate(Sende r: TObject);
begin
inherited; // never goes in here
...
end;
Thanks, Tom.
Here's some code snippets:
with TfrmSchedGridConfig.Create
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.FormCr
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
//Viktor
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
Oh, and tell me where does this code come from???
with TfrmSchedGridConfig.Create
try
if not (ShowModal = mrCancel) then begin
...
end;
finally
Free;
end;
vik
ASKER
Vik,
Thanks for your help. I just found what it was, the form create had somehow got disconnected in the object inspector...
Tom.
Thanks for your help. I just found what it was, the form create had somehow got disconnected in the object inspector...
Tom.
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;
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
-------------------------
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
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
//Viktor Ivanov
ASKER
Vic, thanks for all the work, answer so I can grade, Tom.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Regards,
Viktor Ivanov