Vidi:
Code:
program Project1;
uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {Form2};
{$R *.res}
begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.CreateForm(TForm2, Form2);
Application.Run;
end.
Trebalo bi po ovome da je ok, a?
Ali i dalje: "
Class TForm2 not found"!!!
Ovo sam radio baš po tvome...
U tabeli mi je za polje
Form vrednost
TForm2.
A vidi malo i ovde:
Code:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, ADODB, Menus, Unit2;
type
TForm1 = class(TForm)
mnuMain: TMainMenu;
tblMenu: TADOTable;
procedure FormCreate(Sender: TObject);
procedure MenuClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
private
{ Private declarations }
public
FormNames: TStringList;
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
Form2: TForm2;
function FindMenuItem(Parent: TMenuItem; ACaption: String): TMenuItem;
var
I: Integer;
begin
I := 0;
Result := Parent.Find(ACaption);
while (Result = nil) and (I < Parent.Count) do
begin
Result := FindMenuItem(Parent.Items[I], ACaption);
Inc(I);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
M, P: TMenuItem;
ParentName, MenuName, FormName: String;
begin
FormNames := TStringList.Create;
while not tblMenu.Eof do
begin
ParentName := tblMenu.FieldByName('Parent').AsString;
MenuName := tblMenu.FieldByName('Meni').AsString;
FormName := tblMenu.FieldByName('Form').AsString;
P := FindMenuItem(mnuMain.Items, ParentName);
if P = nil then
begin
P := TMenuItem.Create(mnuMain);
P.Name := ParentName;
P.Caption := P.Name;
mnuMain.Items.Add(P);
end;
M := TMenuItem.Create(mnuMain);
M.Name := MenuName;
M.Caption := M.Name;
P.Add(M);
if FormName <> '' then
begin
FormNames.Add(FormName);
M.Tag := FormNames.Count - 1;
M.OnClick := MenuClick;
end;
tblMenu.Next;
end;
end;
procedure TForm1.MenuClick(Sender: TObject);
var
F: TForm;
C: TComponentClass;
begin
F := nil;
try
C := TComponentClass(FindClass(FormNames[TMenuItem(Sender).Tag]));
Application.CreateForm(C, F);
F.ShowModal;
finally
if Assigned(F) then
FreeAndNil(F);
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
if Assigned(FormNames) then
FreeAndNil(FormNames);
end;
end.
I šta misliš, gde sam pogrešio?!
Someone's sitting in the shade today because someone planted a tree a long time ago.