T
terry_zhou82
Unregistered / Unconfirmed
GUEST, unregistred user!
我的代码如下:想得到的功能是每次开机都通过ONCREATE属性检查是否在添加到启动组,如果是的话,则CHECKBOX1.CHECKED,由于CHECKBOX1的控件是动态创建的,所以每次总是出错。请大侠们帮我看看那,谢谢了private procedure CheckboxPress(Sender:TObject); procedure CreateCheckBox; public { Public declarations } end;var Form1: TForm1;implementation var reg:TRegistry; Checkbox1 :TCheckbox;{$R *.dfm}procedure TForm1.CheckboxPress(Sender:TObject);begin if TCheckBox(sender).Checked then begin reg:=TRegistry.Create; with reg do begin RootKey:=HKEY_LOCAL_MACHINE; OpenKey('SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/RUN',False); WriteString('ReminDer',paramstr(0)); end; end else begin reg.RootKey:=HKEY_LOCAL_MACHINE; reg.OpenKey('SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/RUN',False); reg.DeleteValue('ReminDer'); reg.Closekey; reg.Free ; end; end;procedure TForm1.CreateCheckBox;begin Checkbox1 :=TCheckbox.Create(StatusBar1); with Checkbox1 do begin Parent :=StatusBar1; Height :=StatusBar1.Height; Width :=StatusBar1.Panels.Items[2].Width+200; Left :=StatusBar1.Left +280; Visible :=True; Caption :='是否添加到启动组!'; TabStop:=false; OnClick:=CheckboxPress;end;end;procedure TForm1.FormCreate(Sender: TObject);beginCreateCheckBox;reg.OpenKey('SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/RUN',False);if reg.KeyExists('ReminDer') then Checkbox1.checked:=true else Checkbox1.Checked :=false;end;问题出在那里啊?