请问“带类型常量”到底是怎么用的?

syx007 2002-12-17 10:16:06
这是一段别人的程序,我把它复制到我的程序中,就出现:
[Error] PresideForm.pas(163): Left side cannot be assigned to
而在原来程序中没问题,我看不出有什么不同?
?“带类型常量”怎么用呢,帮一下忙!!
procedure TMainForm.Button1Click(Sender: TObject);
const
oldh : DWORD = 0;
begin
if not boolean(oldh) then
begin
oldh := GetWindowLong(Memo1.handle,GWL_WNDPROC);
SetWindowLong(Memo1.handle,GWL_WNDPROC,integer(@s));
end
else
begin
SetWindowLong(Memo1.handle,GWL_WNDPROC,oldh);
oldh := 0;
end;
end;
...全文
41 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chutian 2002-12-17
  • 打赏
  • 举报
回复
implementation

{$R *.dfm}
{$J+} //add this

注:
In the default {$J-} compiler state, typed constants can not have new values assigned to them; they are, in effect, read-only variables. However, if the {$J+} compiler directive is in effect, typed constants can have new values assigned to them; they behave essentially like initialized variables.
findcsdn 2002-12-17
  • 打赏
  • 举报
回复
这个const的作用和c的static的作用差不多属于静态变量。
{$j+} 方法可以,
也可以在project-->option-->compiler-->assignable typed constants 选中。
mouseingrief 2002-12-17
  • 打赏
  • 举报
回复
up

1,184

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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