起步软件技术论坛-X3

 找回密码
 立即注册
搜索
楼主: huixiangtao

【结贴】一个很久都没有解决的问题

[复制链接]
发表于 2009-12-17 15:15:18 | 显示全部楼层
你把"<%=username%>;Biz:\\SCGAITYWGLXT\\BGGL\\BGTJBBGN.FUNC"这个参数作为值传入到
function TtestPermission.Invoke(var Params: array of object): object;
var
  up: array of string;
  s: String;
  lOrgUnit: TOrgUnit;
  lOrgFuncKind:TOrgFuncKind;
  lOrgFuncAllocItems:TOrgFuncAllocItems;
  i:integer;
begin
result:=0;
  s := objectHelper.ToString(Params[0]);
  if s <> nil then
  up :=s.Split([';']);//用户名和功能中不能有“;”号^_^
  lOrgUnit:=TOrgUnit.Create;
  lOrgUnit:=org.OrgSys.OrgSystem.FindUnit('','',up[0]);
   lOrgFuncKind:= TOrgFuncKind.ofkRun;
   lOrgFuncAllocItems := TOrgFuncAllocItems.Create;
   try
    OrgSys.OrgSystem.GetAllFunc(lOrgUnit,lOrgFuncKind,lOrgFuncAllocItems);
    dialogs.ShowMessage(sysutils.IntToStr(lOrgFuncAllocItems.Count));
     for I := 0 to lOrgFuncAllocItems.Count - 1 do
      begin
         if stringutils.PosIgnoreCase(up[1],TOrgFuncAllocItem(lOrgFuncAllocItems.Items).FuncURL)=1 then
        begin
        Result:=1;
        break;
        end;
      end;
  finally
    lOrgFuncAllocItems.Free;
    lOrgUnit.Free;
  end;

end;
这里面能正确返回值么?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-12-17 16:01:57 | 显示全部楼层
能,因为我在BuinessBGTJBB1. jsp中,alert(IsPermission); 的值为1.
我想这就说明正确执行了吧。
回复 支持 反对

使用道具 举报

发表于 2009-12-17 16:07:28 | 显示全部楼层
是的。
如果这些地方都执行了你就在Business.jsp中后面添加的去掉看看。只能这样一点点来排除了。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-12-17 17:02:30 | 显示全部楼层
我逐条注释,发现  X3X.Run("Biz:\\System\\Init.Func", "Biz:\\SCGAITYWGLXT\\BGGL\\BGTJBBGN.FUNC", "", "");这条语句要是注释掉,就不报刚刚的错误了。
但是这条语句很关键,怎么能注释呢。
有一点怀疑:Run函数要把Biz:\\System\\Init.Func功能,也就是系统初始化功能给运行起来。是不是我在系统初始化中做的这些修改和Run函数运行有冲突呢?
回复 支持 反对

使用道具 举报

发表于 2009-12-17 17:35:03 | 显示全部楼层
明天我试试吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-12-17 19:31:17 | 显示全部楼层
找到原因了。但是不知道为什么?
问题就出在下面这段代码中:
function TtestPermission.Invoke(var Params: array of object): object;
var
  up: array of string;
  s: String;
  lOrgUnit: TOrgUnit;
  lOrgFuncKind:TOrgFuncKind;
  lOrgFuncAllocItems:TOrgFuncAllocItems;
  i:integer;
  j:integer;
begin
result:=0;
  s := objectHelper.ToString(Params[0]);
  if s <> nil then
  up :=s.Split([';']);//用户名和功能之间中不能有“;”号^_^
// lOrgUnit:=TOrgUnit.Create;

  lOrgUnit:=org.OrgSys.OrgSystem.FindUnit('','',up[0]);
   lOrgFuncKind:= TOrgFuncKind.ofkRun;
   lOrgFuncAllocItems := TOrgFuncAllocItems.Create;
   try
    OrgSys.OrgSystem.GetAllFunc(lOrgUnit,lOrgFuncKind,lOrgFuncAllocItems);

       for I := 0 to lOrgFuncAllocItems.Count - 1 do
      begin
        for j:=1 to up.Length-1 do
       begin
         if stringutils.PosIgnoreCase(up[j],TOrgFuncAllocItem(lOrgFuncAllocItems.Items).FuncURL)=1 then
        begin
        Result:=1;
        break;
        end;
        end;//end  for j
        if Result=1 then
          break;
       end;

  finally
    lOrgFuncAllocItems.Free;
   // lOrgUnit.Free;
  end;

end;
就是注释的这两句:
// lOrgUnit:=TOrgUnit.Create;
// lOrgUnit.Free;
这两句注释了就不出错了。之前出错,就是因为我create了一下,又free了一下引起的。
但是我就不明白了,为什么会这样?
即便真的不用create,那我create一下到底影响什么了?
回复 支持 反对

使用道具 举报

发表于 2009-12-18 11:15:23 | 显示全部楼层
FindUnit 它本身是从一个已知列表中找到 TOrgUnit的对象,而你 自己创建了一个 TOrgUnit的对象lOrgUnit,lOrgUnit:=org.OrgSys.OrgSystem.FindUnit('','',up[0]); 这句话本身没问题,但是问题出在 lOrgUnit.Free;,这个Free掉的是 FindUnit 的对象而不是你创建出来的lOrgUnit,所以导致内存泄露。所以对于这样的方式 不需要去创建一个 TOrgUnit。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2009-12-18 11:25:21 | 显示全部楼层
哦,深奥。呵呵
多谢,结贴吧!
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Justep Inc.

GMT+8, 2025-7-13 07:51 , Processed in 0.061429 second(s), 13 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表