请解决一个菜鸟的简单问题。高分奉送!!!!(200分)

  • 主题发起人 heidongzhiling
  • 开始时间
H

heidongzhiling

Unregistered / Unconfirmed
GUEST, unregistred user!
我将RadioButton.checked的值读入了注册表,然后我希望在开机的时候读取值赋给RadioButton
可是就是出错。我估计是消息的处理,和交叉影响求解决方法。
我的源码:
uses pop2,registry,smtp1;
{$R *.DFM}
procedure TParaForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true) then
begin
Reg.WriteBool('收发信件',pop1.cnt.Enabled);
end;
end;

procedure TParaForm.FormCreate(Sender: TObject);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true);
ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
end;

procedure TParaForm.RadioButton2Click(Sender: TObject);
begin
pop2.Pop1.Cnt.Enabled:=true;
//也是一个按钮
smtp1.smtp.Button1.Enabled:=true;
end;

procedure TParaForm.RadioButton1Click(Sender: TObject);
begin
pop2.Pop1.Cnt.Enabled:=false;
smtp1.smtp.Button1.Enabled:=false;
end;

end.
 
你是在创建窗口时就读布尔值了,你检查一下你的注册表里有没有这个键值了,没有的话
会出错的。
 
//应该这样 注意释放
procedure TParaForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true) then
begin
Reg.WriteBool('收发信件',pop1.cnt.Enabled);
end;
finally
Reg.CloseKey;
Reg.Free;
end;
end;

procedure TParaForm.FormCreate(Sender: TObject);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true);
ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
finally
Reg.CloseKey;
Reg.Free;
end;
end;
 
我检查了注册表有值,而且可以读出来但是不能在procedure TParaForm.FormCreate(Sender: TObject);
在读出。
我是这样试个
procedure TParaForm.FormCreate(Sender: TObject);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true);
ParaSet.ParaForm.RadioButton3.checked:=Reg.readBool('收发信件');//重点是改成RadioButton3但我的程序功能就实现不了
end;
这样的话不出错!麻烦给我再看看
 
相信“任豆豆”
 
真的,还是不行求大伙了。我都头疼两天了
 
uses pop2,registry,smtp1;
{$R *.DFM}
procedure TParaForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true) then
begin
Reg.WriteBool('收发信件',pop1.cnt.Enabled);
end;

Reg.Free;
end;

procedure TParaForm.FormCreate(Sender: TObject);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true) then
if Reg.KeyExists('收发信件') then
// 看看我要的键是否存在 ?
ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
Reg.Free;
end;

procedure TParaForm.RadioButton2Click(Sender: TObject);
begin
pop2.Pop1.Cnt.Enabled:=true;
//也是一个按钮
smtp1.smtp.Button1.Enabled:=true;
end;

procedure TParaForm.RadioButton1Click(Sender: TObject);
begin
pop2.Pop1.Cnt.Enabled:=false;
smtp1.smtp.Button1.Enabled:=false;
end;
end.
另:贴代码最好自己先整理一下,便于阅读的人,快速找出问题。
 
if Reg.KeyExists('收发信件') then
// 看看我要的键是否存在 ?
加了这个错误是没有了。但是 ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
这始终就没有执行过。
我把它换成if Reg.ValueExists('收发信件') then
// 看看我要的键是否存在
错误又来了。
看来还是不行,我在注册表看了。结果是有,就是不能读出来!求再帮忙分析
 
加一个TRY吧!
要不用单步运行追踪一下!
 
procedure TParaForm.RadioButton1Click(Sender: TObject);
begin
pop2.Pop1.Cnt.Enabled:=false;//它显示问题出在这一行
smtp1.smtp.Button1.Enabled:=false;
end;
其实应该是由于ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
我把它进行了单方面赋值,正常的情况应该是单击按钮,使它产生按钮事件改变它的其他定义,就产生了冲突
问题我想应该如此,可我就不知道有啥方法能解决!
上述是我的想法,可能不对,希望大家给我出注意!!再次谢大家!求继续帮我。。。
 
你好像还是没有表述清楚嘛? 试试下面这个:
procedure TParaForm.FormCreate(Sender: TObject);
var
Reg:TRegistry;
bSend: Boolean;
begin
Reg:=TRegistry.Create;
try
Reg.RootKey := HKEY_LOCAL_MACHINE;
Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true);
try
bSend := Reg.ReadBool('收发信件');
except
bSend := False;
end;
finally
ParaSet.ParaForm.RadioButton1.Checked := bSend;
Reg.CloseKey;
Reg.Free;
end;
end;
 
把错误帖出来看一下!
 
ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
会触发RadioButton1Click事件,在我的程序里也碰到了这个问题,
我设定了一个标记来解决这个问题!
 
其实大家总是去想try 。。。except。。。 finally
真的请相信我觉对不是那个原因!
如果大伙把我写的全部看一篇的话,你们能够解决
 
咦?!还在找答案???? 我贴出的代码你试过了吗????!!!!!!试一试,太懒了!
 
小雨,你也太不相信我呢。我哪有不试之哩我正准备把整个原代码全部贴出来分析
我在找你的油箱,想把它发给你们
 
我的邮箱:yckxzjj@163.com 希望与你多作交流!
 
赋一个全局变量,在FormCreate的时候将注册表读入的值赋给这个全局变量,在FormShow里再根据全局变量值去设置ParaSet.ParaForm.RadioButton1.Checked的值
 
我已经解决问题了,但是使用的是迂回的方法,那里我真的走不通,谁叫我是菜鸟
我现在把我的方法说出,其实很简单。我增加了一个初始化按钮。我把贴子贴出也感谢上面各位的辛苦
整个项目我还是不能全盘拖出!说声遗憾!
procedure TParaForm.FormClose(Sender: TObject;
var Action: TCloseAction);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true) then
begin
Reg.WriteBool('收发信件',pop1.cnt.Enabled);
end;
Reg.Free;
end;

procedure TParaForm.FormCreate(Sender: TObject);
var
Reg:TRegistry;
begin
Reg:=TRegistry.Create;
if Reg.OpenKey('/Software/Microsoft/Windows/CurrentVersion/Run',true) then
// if Reg.KeyExists('收发信件') then
// 看看我要的键是否存在 ?
ParaSet.ParaForm.RadioButton1.Checked:=Reg.readBool('收发信件');
Reg.Free;
end;

procedure TParaForm.RadioButton2Click(Sender: TObject);
begin
//pop2.Pop1.Cnt.Enabled:=true;
// smtp1.smtp.Button1.Enabled:=true;
end;

procedure TParaForm.RadioButton1Click(Sender: TObject);
begin
//pop2.Pop1.Cnt.Enabled:=false;
//smtp1.smtp.Button1.Enabled:=false;
end;
procedure TParaForm.Button1Click(Sender: TObject);
//增加的初始化按钮
begin
if ParaSet.ParaForm.RadioButton1.Checked then
begin
pop2.Pop1.Cnt.Enabled:=false;
smtp1.smtp.Button1.Enabled:=false;
end else
begin
pop2.Pop1.Cnt.Enabled:=true;
smtp1.smtp.Button1.Enabled:=true;
end;
end;
我还是结贴,希望大家以后多帮忙!
 
多人接受答案了。
 
顶部