导航
  • 主页
  • 招聘
  • 语言基础/算法/系统设计
  • 数据库相关
  • 图形处理/多媒体
  • 网络通信/分布式开发
  • VCL组件开发及应用
  • Windows SDK/API
  • 问答

关于条件编译的问题.

Thumb168 2002-05-18 10:51:22
delphi下有没有象C++下的条件编译的指令.
我现在在做一个项目,一些数据在我测试的环境下是固定的.我想开发完毕后更改一下编译条件就可以发布正式版本了.不知道有没有.请大家帮助
...全文
浏览 点赞 收藏 3
写回复
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
ly_liuyang 2002-05-18
{$DEFINE DEBUG}

{$IFDEF DEBUG}
Writeln('Debug is on.'); // this code executes
{$ELSE}
Writeln('Debug is off.'); // this code does not execute
{$ENDIF}

{$UNDEF DEBUG}

{$IFNDEF DEBUG}
Writeln('Debug is off.'); // this code executes

{$ENDIF}
回复
hkhurus 2002-05-18
我说一下吧.... 首先先写一个文件,编译文件如 TEST.PAS
里面就是写 {$DEFINE TEST}


在调用的单元中写
{$I TEST.PAS}

可以在使用编译指令的地方写

{$ifdef test}
DO//程序
{$endif}
{$ifndef text}
NOT DO//程序
{$endif}




回复
zzwu 2002-05-18
有的,以下是Delphi提供的说明及例子:

Two basic conditional compilation constructs closely resemble Pascal's if statement. The first construct

{$IFxxx}
...
{$ENDIF}

causes the source text between {$IFxxx} and {$ENDIF} to be compiled only if the condition specified in {$IFxxx} is True. If the condition is False, the source text between the two directives is ignored.

The second conditional compilation construct:

{$IFxxx}
...
{$ELSE}
...
{$ENDIF}

causes either the source text between {$IFxxx} and {$ELSE} or the source text between {$ELSE} and {$ENDIF} to be compiled, depending on the condition specified by the {$IFxxx}.

Here are some examples of conditional compilation constructs:

{$IFDEF Debug}
Writeln('X = ', X);
{$ENDIF}
{$IFDEF WIN32}
P := SmallPointToPoint(Message.Pos);
{$ELSE}
P := Message.Pos;
{$ENDIF}

You can nest conditional compilation constructs up to 16 levels deep. For every {$IFxxx}, the corresponding {$ENDIF} must be found within the same source file, which means there must be an equal number of {$IFxxx}'s and {$ENDIF}'s in every source file.
回复
发动态
发帖子
Delphi
创建于2007-08-02

4802

社区成员

Delphi 开发及应用
申请成为版主
社区公告
暂无公告