Вниз
Скачать: CL | DM;

Работа с TForm через строку.   Найти похожие ветки 

← →
Фадеева   (2003-06-27 20:09) [0]

Большая просьба разрешить мою проблему: в TForm1 есть кнопка, вызывающая TForm2(через string) и открывающая ее методом ShowModal. И это работает до тех пор пока ShowModal не заменить на метод TForm2.New. Транслятор этот метод не видит. Вопрос: как вызвать TForm2.New?

============
unit Unit1;

interface

uses Unit2, Unit3, Unit4, Unit5,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm1 = class(TForm)
Edit1: TEdit;
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
RegisterClass(Tform2);
RegisterClass(Tform3);
RegisterClass(Tform4);
RegisterClass(Tform5);
end;

procedure TForm1.Button1Click(Sender: TObject);
var f : TFormClass;
begin
f := TFormClass(FindClass(edit1.text));
with f.Create(self) do begin
f := MethodAddress("New");
if f <> nil then
f.ShowModal;
end;
end;

end.

=========
=========

unit Unit2;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
TForm2 = class(TForm)
Label1: TLabel;
Button1: TButton;
procedure New (const Name : string);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;


implementation

{$R *.dfm}

procedure TForm2.New(const Name : string);
begin
Label1.Caption := Name;
showmodal;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
close;
end;

end.

Заранее большое спасибо за внимание.


← →
reonid ©   (2003-06-27 20:17) [1]

Вот этого я не понял:

f := MethodAddress("New");
if f <> nil then
f.ShowModal; // f - это же теперь указатель на метод ???


← →
reonid ©   (2003-06-27 20:24) [2]

Кстати, какой ещё транслятор???
Ещё - зачем ты пытаешься найти метод New у класса TForm1?
там его нет.


← →
Palladin ©   (2003-06-27 23:38) [3]

а где объявление TFormClass?
TForm2.New можно вызвать только лишь объявив его методом класса или конструктором...
иначе нужно создать объект...



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

Скачать: CL | DM;



Память: 0.45 MB
Время: 0.012 c
1-31257
zolotov
2003-06-30 00:20
2003.07.10
Customize ToolBar2000


1-31242
Relaxxx
2003-06-29 17:36
2003.07.10
Чтение с файла


3-31097
Sirus
2003-06-17 08:00
2003.07.10
При работе диск фрагментируется...


1-31325
hex_for_delphi
2003-06-26 17:20
2003.07.10
как сделать цикл шагами


3-31108
denis24
2003-06-17 14:41
2003.07.10
sql.add....




   Наверх