Fórum tMenuItem #200667
12/12/2003
0
Olá pessoal
Preciso de uma ajuda.
Como faço para ler uma tabela (obviamente ela tem poucos registros) e à partir de algum campo criar tMenuItem dentro de um tMainMenu?
Valeu
Preciso de uma ajuda.
Como faço para ler uma tabela (obviamente ela tem poucos registros) e à partir de algum campo criar tMenuItem dentro de um tMainMenu?
Valeu
Nigro
Curtir tópico
+ 0
Responder
Posts
12/12/2003
Fabio.hc
Eu tenho esta rotina:
E a estrutura da tabela é:
PRG_COD: SMALLINT
PRG_MENU: SMALLINT
PRG_TITULO: VARCHAR(30)
unit U_FrmMenu;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Db, IBCustomDataSet, IBQuery, Menus, IBDatabase;
type
TForm3 = class(TForm)
qryMenu: TIBQuery;
Button1: TButton;
Acesso: TIBDatabase;
IBTrans: TIBTransaction;
qryMenuPRG_MENU: TSmallintField;
qryMenuPRG_TITULO: TIBStringField;
qryMenuPRG_COD: TSmallintField;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure MenuVirt;
procedure MyPopupHandler(Sender: TObject);
function aceProg(paraForm:Integer):boolean;
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form3: TForm3;
MyMainMenu: TMainMenu;
MySubItems: array[0..53] of TMenuItem;
implementation
uses U_frmSistema;
{$R *.DFM}
procedure TForm3.FormCreate(Sender: TObject);
begin
qryMenu.Open;
end;
procedure TForm3.Button1Click(Sender: TObject);
begin
MenuVirt;
end;
procedure TForm3.MenuVirt;
var men, smn: integer;
MyItem: array[0..9] of TMenuItem;
i: Integer;
begin
smn:=0;
if MyMainMenu <> nil then
MyMainMenu.Destroy;
MyMainMenu:= TMainMenu.Create(Self);
qryMenu.First;
i:=99;
men:=-1;
while not qryMenu.Eof do
begin
if i <> qryMenuPRG_MENU.Value-1 then
begin
men:=men+1;
i:=qryMenuPRG_MENU.Value-1;
smn:=0;
MyItem[men] := TMenuItem.Create(Self);
case i of
0: MyItem[men].Caption := ´&Vendas´;
1: MyItem[men].Caption := ´&Cadastros´;
2: MyItem[men].Caption := ´Cai&xas´;
3: MyItem[men].Caption := ´&Estoque´;
4: MyItem[men].Caption := ´&Relatórios´;
5: MyItem[men].Caption := ´Con&figurações´;
end;
MyMainMenu.Items.Add(MyItem[men]);
end;
smn:=smn+1;
MySubItems[smn] := TMenuItem.Create(Self);
MySubItems[smn].Caption := qryMenuPRG_TITULO.Value;
MySubItems[smn].Tag := qryMenuPRG_COD.Value;
MySubItems[smn].OnClick := MyPopUpHandler;
MyMainMenu.Items[men].Add(MySubItems[smn]);
qryMenu.Next;
end;
MyItem[men+1] := TMenuItem.Create(Self);
MyItem[men+1].Caption := ´&Sair´;
MyItem[men+1].Tag := 0;
MyItem[men+1].OnClick := MyPopUpHandler;
MyMainMenu.Items.Add(MyItem[men+1]);
end;
procedure TForm3.MyPopupHandler(Sender: TObject);
begin
with Sender as TMenuItem do
aceProg(Tag)
end;
function TForm3.aceProg(paraForm: Integer): boolean;
begin
case paraForm of
//=====================================================
0:Close
//=====================================================
1:if frmSistema=nil then
frmSistema:=TfrmSistema.Create(application)
else
frmSistema.Show;
//=====================================================
2:if FrmPrograma=nil then
FrmPrograma:=TFrmPrograma.Create(application)
else
FrmPrograma.Show;
//=====================================================
3:
...
...
end;
Result:=True;
end;
end.
E a estrutura da tabela é:
PRG_COD: SMALLINT
PRG_MENU: SMALLINT
PRG_TITULO: VARCHAR(30)
Responder
Gostei + 0
12/12/2003
Nigro
up
Responder
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)