奇怪的指针,还是别的什么? (100分)

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

yylg

Unregistered / Unconfirmed
GUEST, unregistred user!
有一段程序:<br>type<br>&nbsp; TCtr = record<br>&nbsp; &nbsp; v: real;<br>&nbsp; &nbsp; used:boolean;<br>&nbsp; &nbsp; v_used:^TCheckBox;<br>&nbsp; &nbsp; v_set:^TComboBox;<br>&nbsp; end;<br>...<br>var <br>&nbsp; F_zldy: TF_zldy;<br>&nbsp; ValueChanged:Boolean;<br>&nbsp; OptionsValue:array [0..8,0..31] of real =( 。。。预定义的值,省略。。。);<br>&nbsp; pCtr:array [0..8] of TCtr;<br>...<br>procedure TF_zldy.FormCreate(Sender: TObject);<br>begin<br>&nbsp; LinkCtr;<br>&nbsp; InitValue;<br>&nbsp; InitCtr;<br>end;<br><br>//这里用指针指向相应的控件,如c_used0(TCheckBox)和cb_set0(TComboBox)等,以便以后统一管理<br>procedure TF_zldy.LinkCtr;<br>begin<br>&nbsp; with pCtr[0] do begin v_used:=@c_used0; v_set:=@cb_set0; end;<br>&nbsp; with pCtr[1] do begin v_used:=@c_used1; v_set:=@cb_set1; end;<br>&nbsp; with pCtr[2] do begin v_used:=@c_used2; v_set:=@cb_set2; end;<br>&nbsp; with pCtr[3] do begin v_used:=@c_used3; v_set:=@cb_set3; end;<br>&nbsp; with pCtr[4] do begin v_used:=@c_used4; v_set:=@cb_set4; end;<br>&nbsp; with pCtr[5] do begin v_used:=@c_used5; v_set:=@cb_set5; end;<br>&nbsp; with pCtr[6] do begin v_used:=@c_used6; v_set:=@cb_set6; end;<br>&nbsp; with pCtr[7] do begin v_used:=@c_used7; v_set:=@cb_set7; end;<br>&nbsp; with pCtr[8] do begin v_used:=@c_used8; v_set:=@cb_set8; end;<br>end;<br><br>procedure TF_zldy.InitValue;<br>begin<br>&nbsp; ValueChanged := false;<br>end;<br><br>procedure TF_zldy.InitCtr;<br>var i,j:integer;<br>&nbsp; &nbsp; SL: TStrings;<br>begin<br>&nbsp; With Qry_zldy.SQL do<br>&nbsp; begin<br>&nbsp; &nbsp; Clear;<br>&nbsp; &nbsp; Add(...用Select打开一张表...);<br>&nbsp; end;<br>&nbsp; Qry_zldy.Open ;<br><br>&nbsp; with Qry_zldy do<br>&nbsp; begin<br>&nbsp; &nbsp; for i:=0 to 8 do<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; with pCtr do<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; v_set^.itemindex := fieldbyname('s'+inttostr(i)).AsInteger;<br>&nbsp; &nbsp; &nbsp; &nbsp; v_used^.checked := fieldbyname('u'+inttostr(i)).Asboolean;<br>//问题就出现在这里,当执行了这一句后,ValueChanged 的值自动被改变成了所取的字段的值了,如True,我试着换变量名,换变量定义的位置,都不行!!!<br>&nbsp; &nbsp; &nbsp; end;<br>&nbsp; &nbsp; end<br>&nbsp; end;<br>end;<br><br>是我使用指针的方法不对,还是编译器有毛病?请高手们指教。<br><br>我的Email: YYLG@sdu.edu.cn
 
從你的聲明看: <br>var <br>&nbsp; F_zldy: TF_zldy;<br>&nbsp; ValueChanged:Boolean;<br>ValueChanged 是個獨立變量, 除非你在尋里還有修改它的地方, 要不然, 不可能啊!
 
ValueChanged是这个窗口的全局变量,可我执行这段程序时真的很神秘的自动被改变了。
 

Similar threads

后退
顶部