(仅有十个大子可送!怪寒掺),程序改了一下午都没改对,气死老夫。各位谁给分析一下下面的代码,我把动态生成的statictext放到scrollbo (50分)

  • 主题发起人 主题发起人 tl_lyq
  • 开始时间 开始时间
T

tl_lyq

Unregistered / Unconfirmed
GUEST, unregistred user!


if (((sender as tstatictext).top mod 31)<=15) then
(sender as tstatictext).top:=(sender as tstatictext).top-((sender as tstatictext).top mod 31)
else
(sender as tstatictext).top:=(sender as tstatictext).top+31-((sender as tstatictext).top mod 31);

if (((sender as tstatictext).left mod 66)<=33) then
(sender as tstatictext).left:=(sender as tstatictext).left-((sender as tstatictext).left mod 66)
else
(sender as tstatictext).left:=(sender as tstatictext).left+66-((sender as tstatictext).left mod 66);
 
给你把代码清理一下:
var
st: TStaticText;
begin
st := Sender as TStaticText;
if (st.top mod 31) <= 15 then
st.top := st.top - st.top mod 31 else
st.top := st.top - st.top mod 31 + 33;

if (st.Left mod 66) <= 33 then
st.Left := st.Left - st.Left mod 66 else
st.Left := st.Left - st.Left mod 66 + 66;
...
自己把代码看看清楚作了什么,你想要作什么,再提问题
(maybe: st.Parent := Form1
st.BringToFront
I don't know)
end;
 
报错,invalid class typecast
 
加上判断
if Sender is TStaticText then
begin
....
 
报错,invalid class typecast
我把st:=sender as tstatictext放在 form1.create中.为何不行
报错,invalid class typecast
我把st:=sender as tstatictext放在 form1.create中.为何不行
报错,invalid class typecast
我把st:=sender as tstatictext放在 form1.create中.为何不行
报错,invalid class typecast
我把st:=sender as tstatictext放在 form1.create中.为何不行
报错,invalid class typecast
我把st:=sender as tstatictext放在 form1.create中.为何不行
报错,invalid class typecast
我把st:=sender as tstatictext放在 form1.create中.为何不行
 
if not (Sender is TStaticText) then Exit;
st := TStaticText(Sender);
 
var
i: integer;
begin
for i:=0 to ControlCount-1 do
if Controls is TStaticText then
begin
if ((Controls as TStaticText).top mod 31) <= 15 then
(Controls as TStaticText).top :=(Controls as TStaticText).top - (Controls as TStaticText).top mod 31
else
(Controls as TStaticText).top := (Controls as TStaticText).top - (Controls as TStaticText).top mod 31 + 33;

if ((Controls as TStaticText).Left mod 66) <= 33 then
(Controls as TStaticText).Left := (Controls as TStaticText).Left - (Controls as TStaticText).Left mod 66
else
(Controls as TStaticText).Left := (Controls as TStaticText).Left - (Controls as TStaticText).Left mod 66 + 66;
end;
end;
 
后退
顶部