为什么这样做不能控制菜单(200分)

  • 主题发起人 主题发起人 gghhjj
  • 开始时间 开始时间
G

gghhjj

Unregistered / Unconfirmed
GUEST, unregistred user!
表1
id name password
表2
id actioncap actionen actionvi
n 为id,drf返回值
procedure Tmain.FormCreate(Sender: TObject);
var i:integer;
begin
for i:=0 to actionlist1.ActionCount-1 do
begin
with main.ADOQuery1 do
begin
close;
sql.clear;
sql.add('select * from rig where id='+''''+n+'''');
sql.add('and actioncap='+''''+taction(actionlist1.Actions).caption+'''');
open;
if adoquery1.RecordCount=1 then taction(actionlist1.Actions).enabled:=adoquery1.fieldbyname('actionen').asboolean;

end;

end;
end;
用f7调试,通过但不能控制菜单
begin
Application.Initialize;
Application.CreateForm(Tdrf, drf);//登入

Application.CreateForm(Tmain, main);//主窗口
Application.Run;

end.
 
RecordCount一般不一定能够得到正确的数值,使用ISEmpty判断更好一些。
 
非要使用RecordCount,那么首先使用Last一下,就会得到正确数值了。
否则恒为-1
 
TDataSet.IsEmpty比较好
 
好象不是recordcount的问题。
 
可能是你的字段actioncap内容和taction(actionlist1.Actions).caption比较时出的
问题,你的actioncap可能是char类型,和string类型的caption比较时不一致。
你查一下,应该adoquery1.RecordCount=0,总找不到记录。
 
可是我用f7每次都发现n为空‘’实际是不为空的
 
n在哪定义了?类型?
 
unit unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, ToolWin, StdCtrls, ActnList, ImgList, Menus, Db, ADODB;

type
Tmain = class(TForm)
MainMenu1: TMainMenu;
N1: TMenuItem;
N2: TMenuItem;
N3: TMenuItem;
N4: TMenuItem;
N5: TMenuItem;
N6: TMenuItem;
N7: TMenuItem;
N8: TMenuItem;
N9: TMenuItem;
N10: TMenuItem;
N16: TMenuItem;
N11: TMenuItem;
N12: TMenuItem;
N13: TMenuItem;
N14: TMenuItem;
N15: TMenuItem;
N17: TMenuItem;
N18: TMenuItem;
N19: TMenuItem;
N20: TMenuItem;
N21: TMenuItem;
N22: TMenuItem;
N23: TMenuItem;
N24: TMenuItem;
N25: TMenuItem;
N26: TMenuItem;
N27: TMenuItem;
ActionList1: TActionList;
ImageList1: TImageList;
Edit1: TEdit;
Label1: TLabel;
StatusBar1: TStatusBar;
CoolBar1: TCoolBar;
ToolBar1: TToolBar;
ToolButton1: TToolButton;
ToolButton2: TToolButton;
ToolButton3: TToolButton;
ToolButton4: TToolButton;
ToolButton5: TToolButton;
ToolButton6: TToolButton;
ToolButton7: TToolButton;
ToolButton8: TToolButton;
ADOQuery1: TADOQuery;
Action1: TAction;
Action2: TAction;
Action3: TAction;
Action4: TAction;
Action5: TAction;
Action6: TAction;
Action7: TAction;
Action8: TAction;
Action9: TAction;
Action10: TAction;
Action11: TAction;
Action12: TAction;
Action13: TAction;
Action14: TAction;
Action15: TAction;
Action16: TAction;
Action17: TAction;
Action18: TAction;
Action19: TAction;
Action20: TAction;
Action21: TAction;
Action22: TAction;
Action23: TAction;
Action24: TAction;
Action25: TAction;
procedure FormCreate(Sender: TObject);
procedure Action2Execute(Sender: TObject);
procedure Action3Execute(Sender: TObject);
procedure Action7Execute(Sender: TObject);
procedure Action4Execute(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }

end;

var
main: Tmain;n:string;
implementation

uses jpcx,zcxs, dr, lr;

{$R *.DFM}
 
嘿嘿,少空格了:
sql.add('select * from rig where id='+''''+n+'''');
sql.add('and actioncap='+''''+taction(actionlist1.Actions).caption+'''');
~~
 
Add添加,无所谓空格的。
 
不错,没有看见n,是不是n=i了?
procedure Tmain.FormCreate(Sender: TObject);
var
i: integer;
begin
for i := 0 to actionlist1.ActionCount - 1 do
begin
with main.ADOQuery1 do
begin
close;
sql.clear;
n:=IntToStr(i);
sql.add('select * from rig where id=' + '''' + n + '''');
sql.add('and actioncap=' + '''' + taction(actionlist1.Actions).caption + '''');
open;
if adoquery1.IsEmpty=False then taction(actionlist1.Actions).enabled := adoquery1.fieldbyname('actionen').asboolean;
end;

end;
end;
 
不对,actioncap已经决定了是哪一个Action了,n是代表用户id吧,在那里赋值呀?[:)]
 
同意yzhshi,转换后要除掉空格吧,
n:=trim(IntToStr(i));
 
TO yzhshi:
呵呵,老兄说得对,Add是不用管空格的,偶都忙晕了。

TO gghhjj:
Application.Initialize;
Application.CreateForm(Tdrf, drf);//登入
Application.CreateForm(Tmain, main);//主窗口
Application.Run;
从你的窗口创建顺序看,drf窗体才是主窗体,且drf所在单元dr可能未引用main窗体所在单元,
这样unit1.n的值只能是初始化值'',你检查一下你的代码,把dr单元的代码也贴出来看看

 
Application.Initialize;
Application.CreateForm(Tdrf, drf);
Application.CreateForm(Tlrf, lrf);
Application.CreateForm(Tjpcxf, jpcxf);
Application.CreateForm(Tzcxsf, zcxsf);

Application.CreateForm(Twcpf, wcpf);
Application.CreateForm(Tmain, main);
Application.Run;
 
把sql语句savetofile看看,肯定你的n有问题
 
后退
顶部