编译时提出警告,信息如下: |
答題得分者是:Fishman
|
zouhw
一般會員 發表:6 回覆:13 積分:3 註冊:2004-07-12 發送簡訊給我 |
[Warning] unitMainForm.pas(277): Variable 'Reg' might not have been initialized
[Warning] unitMainForm.pas(281): Return value of function 'TMainF.RegistryDebug' might be undefined 程序代码:
function TMainf.RegistryDebug():boolean;
var
Reg:Tregistry;
name, code, mytest, KeyName : string;
i : integer;
begin
try
//创建注册表,有该键则读取,无则创建
Reg:=Tregistry.Create ;
Reg.RootKey :=hkey_local_machine;
KeyName := 'SoftWare\BatchMailer\Registry';
if Reg.OpenKey(KeyName,false) then
begin
Name:=Reg.ReadString('UsrName');
Code:=Reg.ReadString('Passwd');
if Code = '0' then
result := false
else
if name = Encrypt( Code ) then
result := true;
Registrystring := Name;
end
else
begin
if Reg.OpenKey( KeyName, true ) then
begin
randomize;
for i := 1 to 12 do
mytest := mytest char( random( 15 ) 70 );
Reg.WriteString('UsrName',mytest);
Reg.WriteString('Passwd','0');
result := false;
end;
end;
finally
Reg.CloseKey;
Reg.Free;
end; end; 如何处理解决,请高手赐教! 一切皆有可能!
------
dsf |
Fishman
尊榮會員 發表:120 回覆:1949 積分:2163 註冊:2006-10-28 發送簡訊給我 |
Hi zouhw, Try to correct you code as below :
function RegistryDebug():boolean; var Reg:Tregistry; name, code, mytest, KeyName : string; i : integer; re : Boolean; begin re := False; Reg:=Tregistry.Create ; try Reg.RootKey :=hkey_local_machine; KeyName := 'SoftWare\BatchMailer\Registry'; if Reg.OpenKey(KeyName,false) then begin Name:=Reg.ReadString('UsrName'); Code:=Reg.ReadString('Passwd'); if Code = '0' then re := false else if name = Encrypt( Code ) then re := true; Registrystring := Name; end else begin if Reg.OpenKey( KeyName, true ) then begin randomize; for i := 1 to 12 do mytest := mytest char( random( 15 ) 70 ); Reg.WriteString('UsrName',mytest); Reg.WriteString('Passwd','0'); re := false; end; end; finally Reg.CloseKey; Reg.Free; Result := re; end; end;---------------------------------- 小弟才疏學淺,若有謬誤尚請不吝指教 ----------------------------------
------
Fishman |
zouhw
一般會員 發表:6 回覆:13 積分:3 註冊:2004-07-12 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |