L
liwowo
Unregistered / Unconfirmed
GUEST, unregistred user!
全局类结构
unit g_class_u;
interface
uses classes,SysUtils,Controls,mydata;
Type
Tg_class=class(TObject)
public
class function create_G(usrcode:string):Tg_class;
function findpwd(Ival:integer):boolean;
destructor Destroy
override;
private
mypwr:array of integer;
constructor Create(val:string);//输入权限组
end;
var g_class:Tg_class;
implementation
constructor Tg_class.Create(val: string);
var
Ssqlstr:string;
Inum:integer;
begin
inherited Create;
Ssqlstr:='select cFnNo from sysfunction where cFnno in (select CFnno from g_s where Gno='+val+') ';
with DataModule1.ADOQuery1 do
begin
close;
sql.clear;
sql.add(Ssqlstr);
open ;
if recordcount=0 then
begin
setlength(mypwr,1);
mypwr[0]:=0;
exit;
end;
setlength(mypwr,recordcount);
first;
for Inum:=0 to recordcount do
begin
mypwr[Inum]:=fieldbyname('cFnNo').asinteger;
next;
end;
close;
end;
end;
class function Tg_class.create_G(usrcode: string): Tg_class;
begin
if (g_class=nil) then
g_class:=Tg_class.create(usrcode);
result:=g_class;
end;
destructor Tg_class.Destroy;
begin
// setLength(myPwr,0);
// myPwr:=nil;
// inherited Destroy;
end;
function Tg_class.findpwd(Ival: integer): boolean;
var
Inum:integer;
begin
for Inum:=low(mypwr) to high(mypwr) do
begin
if mypwr[Inum]=Ival then
begin
result:=true;
exit;
end;
end;
result:=false;
end;
end.
然后在一个窗体中
procedure TMyForm1.FormShow(Sender: TObject);
begin
if g_class=nil then
g_class:=Tg_class.create_G(grpname);
end;
procedure TMyForm1.FormDestroy(Sender: TObject);
begin
if g_class<>nil then
FreeAndNil(g_class);
end;
怎么会出现错误呢! 各位帮着看看 我用是单例模式写的全局类 为什么我退出释放g_class的时候会出错!
unit g_class_u;
interface
uses classes,SysUtils,Controls,mydata;
Type
Tg_class=class(TObject)
public
class function create_G(usrcode:string):Tg_class;
function findpwd(Ival:integer):boolean;
destructor Destroy
override;
private
mypwr:array of integer;
constructor Create(val:string);//输入权限组
end;
var g_class:Tg_class;
implementation
constructor Tg_class.Create(val: string);
var
Ssqlstr:string;
Inum:integer;
begin
inherited Create;
Ssqlstr:='select cFnNo from sysfunction where cFnno in (select CFnno from g_s where Gno='+val+') ';
with DataModule1.ADOQuery1 do
begin
close;
sql.clear;
sql.add(Ssqlstr);
open ;
if recordcount=0 then
begin
setlength(mypwr,1);
mypwr[0]:=0;
exit;
end;
setlength(mypwr,recordcount);
first;
for Inum:=0 to recordcount do
begin
mypwr[Inum]:=fieldbyname('cFnNo').asinteger;
next;
end;
close;
end;
end;
class function Tg_class.create_G(usrcode: string): Tg_class;
begin
if (g_class=nil) then
g_class:=Tg_class.create(usrcode);
result:=g_class;
end;
destructor Tg_class.Destroy;
begin
// setLength(myPwr,0);
// myPwr:=nil;
// inherited Destroy;
end;
function Tg_class.findpwd(Ival: integer): boolean;
var
Inum:integer;
begin
for Inum:=low(mypwr) to high(mypwr) do
begin
if mypwr[Inum]=Ival then
begin
result:=true;
exit;
end;
end;
result:=false;
end;
end.
然后在一个窗体中
procedure TMyForm1.FormShow(Sender: TObject);
begin
if g_class=nil then
g_class:=Tg_class.create_G(grpname);
end;
procedure TMyForm1.FormDestroy(Sender: TObject);
begin
if g_class<>nil then
FreeAndNil(g_class);
end;
怎么会出现错误呢! 各位帮着看看 我用是单例模式写的全局类 为什么我退出释放g_class的时候会出错!