求下列代码的最简短的写法?谢谢!

ahpei 2003-10-20 08:23:53
大家注意看下列代码,求最简短的写法!谢谢!
statusBar1.Panels[0].Text := 'x='+inttostr(x)+' y='+inttostr(y);
case y of
0..32 : case x of
0..32 : begin SetCurRect(0,0); statusBar1.Panels[1].Text := '行:1 列:1'; end;
33..64 : begin SetCurRect(32,0);statusBar1.Panels[1].Text := '行:1 列:2'; end;
65..96 : begin SetCurRect(64,0);statusBar1.Panels[1].Text := '行:1 列:3'; end;
97..128 : begin SetCurRect(96,0);statusBar1.Panels[1].Text := '行:1 列:4'; end;
129..160 : begin SetCurRect(128,0);statusBar1.Panels[1].Text := '行:1 列:5'; end;
161..192 : begin SetCurRect(160,0);statusBar1.Panels[1].Text := '行:1 列:6'; end;
193..224 : begin SetCurRect(192,0);statusBar1.Panels[1].Text := '行:1 列:7'; end;
225..256 : begin SetCurRect(224,0);statusBar1.Panels[1].Text := '行:1 列:8'; end;
end;
33..64 : case x of
0..32 : begin SetCurRect(0,32);statusBar1.Panels[1].Text := '行:2 列:1'; end;
33..64 : begin SetCurRect(32,32);statusBar1.Panels[1].Text := '行:2 列:2'; end;
65..96 : begin SetCurRect(64,32);statusBar1.Panels[1].Text := '行:2 列:3'; end;
97..128 : begin SetCurRect(96,32);statusBar1.Panels[1].Text := '行:2 列:4'; end;
129..160 : begin SetCurRect(128,32);statusBar1.Panels[1].Text := '行:2 列:5';end;
161..192 : begin SetCurRect(160,32);statusBar1.Panels[1].Text := '行:2 列:6';end;
193..224 : begin SetCurRect(192,32);statusBar1.Panels[1].Text := '行:2 列:7';end;
225..256 : begin SetCurRect(224,32);statusBar1.Panels[1].Text := '行:2 列:8';end;
end;
65..96 : case x of
0..32 : begin SetCurRect(0,64);statusBar1.Panels[1].Text := '行:3 列:1'; end;
33..64 : begin SetCurRect(32,64);statusBar1.Panels[1].Text := '行:3 列:2'; end;
65..96 : begin SetCurRect(64,64);statusBar1.Panels[1].Text := '行:3 列:3'; end;
97..128 : begin SetCurRect(96,64);statusBar1.Panels[1].Text := '行:3 列:4'; end;
129..160 : begin SetCurRect(128,64);statusBar1.Panels[1].Text := '行:3 列:5';end;
161..192 : begin SetCurRect(160,64);statusBar1.Panels[1].Text := '行:3 列:6';end;
193..224 : begin SetCurRect(192,64);statusBar1.Panels[1].Text := '行:3 列:7';end;
225..256 : begin SetCurRect(224,64);statusBar1.Panels[1].Text := '行:3 列:8';end;
end;
...全文
77 22 打赏 收藏 转发到动态 举报
写回复
用AI写文章
22 条回复
切换为时间正序
请发表友善的回复…
发表回复
hthunter 2003-11-03
  • 打赏
  • 举报
回复
该结了吧?
hthunter 2003-10-23
  • 打赏
  • 举报
回复
sorry, 把Result := Dec(Result);改成Dec(Result);就可以了
ahpei 2003-10-22
  • 打赏
  • 举报
回复
看起来是很有规律,可是我想很久都想不出来啊,请大家帮忙帮忙。谢谢大家!
ly_liuyang 2003-10-21
  • 打赏
  • 举报
回复
看看规律了,灵活使用Tag属性会减少不少代码的
qqh198001 2003-10-21
  • 打赏
  • 举报
回复
学习
fhuibo 2003-10-21
  • 打赏
  • 举报
回复
study
qiume 2003-10-21
  • 打赏
  • 举报
回复
应该说还是比较有规律的,自己看一下了
wooden954 2003-10-21
  • 打赏
  • 举报
回复
晚了上步哈
CloneCenter 2003-10-21
  • 打赏
  • 举报
回复
找出规律,然后用数学的方法实现,或者是改变你的数据结构,代码会少很多。
ahpei 2003-10-20
  • 打赏
  • 举报
回复
if ((x mod 32) = 0) and (i > 0) then Result := Dec(Result);
Dec是procedure而不是function,返回值???

还有,你写的这个是错误的,不是正确的结果!谢谢!
很土 2003-10-20
  • 打赏
  • 举报
回复
最简单的方法是初始化一个数组, 以后直接调用数组值即可.
ahpei 2003-10-20
  • 打赏
  • 举报
回复
PF! 试一下就给分.
g58521547 2003-10-20
  • 打赏
  • 举报
回复
看来只有学习高手了
hthunter 2003-10-20
  • 打赏
  • 举报
回复
嘿嘿,嘿嘿
tanqth 2003-10-20
  • 打赏
  • 举报
回复
hthunter(核桃) ( )
动作真快
hmily1688 2003-10-20
  • 打赏
  • 举报
回复
被楼上的给抢了
hthunter 2003-10-20
  • 打赏
  • 举报
回复
上面写错了一点,忘了考虑0的情况,改正并更简:
var
function Multi(i: Integer): Integer;
begin
Result := x div 32;
if ((x mod 32) = 0) and (i > 0) then Result := Dec(Result);
end;
begin
...
SetCurRect(Multi(x) * 32, Multi(y) * 32); //ft,上面这里还少了一个分号,哈哈
statusBar1.Panels[1].Text := Format('行:%d 列:%d', [Multi(y) + 1, Multi(x) + 1]);
...
end;
hthunter 2003-10-20
  • 打赏
  • 举报
回复
上面写错了一点,忘了考虑0的情况,改正并更简:
var
function Multi(i: Integer): Integer;
begin
Result := x div 32;
if ((x mod 32) = 0) and (i > 0) then Result := Dec(Result);
end;
begin
...
SetCurRect(Multi(x) * 32, Multi(y) * 32)
statusBar1.Panels[1].Text := Format('行:%d 列:%d', [Multi(y) + 1, Multi(x) + 1]);
...
end;
hthunter 2003-10-20
  • 打赏
  • 举报
回复
var
x1, y1: Integer;
begin
...
x1 := (x div 32);
if ((x mod 32) = 0) //刚好是32的整数倍时
then x1 := Dec(x1);
y1 := (y div 32);
if ((y mod 32) = 0) //刚好是32的整数倍时
then y1 := Dec(y1);
SetCurRect(x1 * 32, y1 * 32)
statusBar1.Panels[1].Text := Format('行:%d 列:%d', [y1 + 1, x1 + 1]);
...
end;
ahpei 2003-10-20
  • 打赏
  • 举报
回复
写出来看看嘛,谢谢!
加载更多回复(2)

5,386

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧