请教一个关于自定义类作为其他类的中函数的参数类型的问题?谢谢帮忙!(100分)

  • 主题发起人 主题发起人 ywan
  • 开始时间 开始时间
Y

ywan

Unregistered / Unconfirmed
GUEST, unregistred user!
各位好,
我自定义一个类如下(在Branch 单元中):
type
mBranch = class (TObject)
private
FbranchId: string;
FdeptId: string;
FdeptName: string;
FgroupName: string;
public
property branchId: string read FbranchId write FbranchId;
property deptId: string read FdeptId write FdeptId;
property deptName: string read FdeptName write FdeptName;
property groupName: string read FgroupName write FgroupName;
end;
然后我UBranch 单元另一个类中的一个函数引用这个类作为一个参数类型,如下:
type
TFrmBranch = class (TForm)
private
function SaveBranchRule(objmBranch:mBranch) :string;
end;
function TFrmBranch.SaveLogic(strDeptName:string;strGroupName:string):string;
var
objCommon:CommonFunc;
objmBranch: mBranch;
objBranchDb:BranchDb;
strBranchId:string;
strDeptId:string;
strRet:string;
//Query:TADOQuery;
begin

objCommon:=CommonFunc.Create;
if (strMode='ND') then
begin
objmBranch:= mBranch.Create;
strDeptId:=objCommon.GetNewNo('Organize','DeptId',3);
strBranchId:= strDeptId +'01';
objmBranch.branchId:= strBranchId;
objmBranch.deptId := strDeptId;
objmBranch.deptName :=strDeptName;
objmBranch.groupName :=strGroupName;
strRet:=SaveBranchRule(objmBranch);
end;
end;
但是执行到最后一行时出现“Invailid variant type”的错误。
请教各位该如何解决这个问题,谢谢!
 
我刚才简单测试了一下,没问题的呀。你看看可能是其它的代码引起的?
我是这样的,把无关的都屏蔽调了:

type
mBranch = class (TObject)
private
FbranchId: string;
FdeptId: string;
FdeptName: string;
FgroupName: string;
public
property branchId: string read FbranchId write FbranchId;
property deptId: string read FdeptId write FdeptId;
property deptName: string read FdeptName write FdeptName;
property groupName: string read FgroupName write FgroupName;
end;
TForm1 = class(TForm)
private
function SaveBranchRule(objmBranch:mBranch) :string;
function SaveLogic(strDeptName:string;strGroupName:string):string;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

function TForm1.SaveLogic(strDeptName:string;strGroupName:string):string;
var
// objCommon:CommonFunc;
objmBranch: mBranch;
// objBranchDb:BranchDb;
strBranchId:string;
strDeptId:string;
strRet:string;
//Query:TADOQuery;
begin

// objCommon:=CommonFunc.Create;
// if (strMode='ND') then
// begin
objmBranch:= mBranch.Create;
// strDeptId:=objCommon.GetNewNo('Organize','DeptId',3);
strBranchId:= strDeptId +'01';
objmBranch.branchId:= strBranchId;
objmBranch.deptId := strDeptId;
objmBranch.deptName :=strDeptName;
objmBranch.groupName :=strGroupName;
strRet:=SaveBranchRule(objmBranch);
// end;
end;
function TForm1.SaveBranchRule(objmBranch:mBranch) :string;
begin
end;
 
跟踪到SaveBranchRule函数里看看,肯定是里面出问题了。
另外你用完了objmBranch要free掉。
 
学习!!
 
多谢几位指教!的确是在SaveBranchRule里的一个函数返回值出了问题。
 
我觉得程序调试得要充分利用跟踪手段,否则会无形中浪费很多时间。
 
后退
顶部