Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2003.10.06;
Скачать: CL | DM;

Вниз

Помогите с ООП   Найти похожие ветки 

 
Olivka ©   (2003-09-25 13:04) [0]

Посмотрите, плиз, сей код - я пытаюсь разобраться с наследованием. Почему ошибка выдается? ;(
Только не ругайте сильно!

program Project2;
uses
Forms,
Unit1 in "Unit1.pas" {Form1},
Unit2 in "Unit2.pas" {Form2},
Unit3 in "Unit3.pas" {Form3};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm3, Form3);
Application.Run;
end.
---------------------------------------------
unit Unit3;
interface
uses...
type
TForm3 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
implementation
uses Unit2;
{$R *.dfm}
procedure TForm3.Button1Click(Sender: TObject);
begin
form2.create(application,1);
end;
end.
-----------------------------------------------
unit Unit1;
interface
uses...
type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
constructor Create(AOwner: TComponent); override;
end;
var
Form1: TForm1;
implementation
uses Unit2;
{$R *.dfm}
constructor TForm1.Create(AOwner: TComponent);
begin
-------access violation------->>>>> inherited;
end;
end.
---------------------------------------------------------------
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Unit1, StdCtrls;
type
TForm2 = class(TForm1)
Label1: TLabel;
private
{ Private declarations }
Field : integer;
public
{ Public declarations }
constructor Create(AOwner: TComponent; param: integer); overload;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
constructor TForm2.Create(AOwner: TComponent; param: integer);
begin
inherited Create(AOwner);
Field := param;
ShowMessage("Field = " + IntToStr(Field));
end;
----------------------------------------------------------------


 
Юрий Федоров ©   (2003-09-25 13:12) [1]

procedure TForm3.Button1Click(Sender: TObject);
begin
form2.create(application,1);
end;


?????


 
Mikhail V   (2003-09-25 13:24) [2]

Form2 := TForm2.Create(Application, 1) ?


 
Murad ©   (2003-09-25 13:31) [3]

Может стоило в TForm2.Create сделать REINTRODUCE a не OVERLOAD


 
icWasya ©   (2003-09-25 13:48) [4]

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Unit1, StdCtrls;
type
TForm2 = class(TForm1)
Label1: TLabel;
private
{ Private declarations }
Field : integer;
public
{ Public declarations }
constructor Create(AOwner: TComponent);override; // добавить
constructor Create(AOwner: TComponent; param: integer); overload;
end;
var
Form2: TForm2;
implementation
{$R *.dfm}

constructor TForm2.Create(AOwner: TComponent; param: integer);
begin
inherited Create(AOwner);
end;

constructor TForm2.Create(AOwner: TComponent; param: integer);
begin
//inherited Create(AOwner); - выкинуть
Create(AOwner);

Field := param;
ShowMessage("Field = " + IntToStr(Field));
end;


 
Murad ©   (2003-09-25 13:55) [5]

2icWasya
Это все к сути дела не относится!
Ошибка была из-за того что при записи
form2.create(application,1); не происходит создания
объекта, а только вызов метода create, а, ссылка на form2
в этот момент нулевая. Т.е. никто еще память даже под объект
не выделил. Правильное решение дал Mikhail V и Юрий Федоров...


 
Olivka ©   (2003-09-25 16:04) [6]

Люди, спасибо, разобралась !:)



Страницы: 1 вся ветка

Текущий архив: 2003.10.06;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.026 c
14-18599
dimon1979
2003-09-18 11:41
2003.10.06
Установка компонент


14-18545
Delirium
2003-09-16 14:26
2003.10.06
Инресетно ...


14-18542
A_n_d_y!!!
2003-08-29 11:33
2003.10.06
Ищю толкового програмиста


3-18262
McSimm2
2003-09-17 15:31
2003.10.06
Кодирование данных


1-18459
Farmotura
2003-09-24 14:09
2003.10.06
Копии формы