这个"begin"为什么可有可无?

sc_arhat 2007-10-18 03:21:55
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation

{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
showMessage('OK');
end;

begin//////////////////////////////////////////这行加上也可以运行,删除也没有错,为什么?

end.

大侠们给讲解一下,谢谢!
...全文
202 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
oushengfen 2007-11-16
  • 打赏
  • 举报
回复
hongqi162

说得对。
xmfan 2007-11-15
  • 打赏
  • 举报
回复
wangxuelid 2007-10-23
  • 打赏
  • 举报
回复
,,,学习,,
eminemlhp 2007-10-22
  • 打赏
  • 举报
回复
呵呵,晕死,大家都不太对的吧。你写上这个begin就会带来问题的:
一个单元是可以有一个initialization节和一个finalization节的,如果你写上了那个begin,你就不能再拥有initialization节(编译都不会通过),而如果没有initialization节,自然也就不能再有finalization节。
huangxw000 2007-10-20
  • 打赏
  • 举报
回复
begin和end相当于{},没有复合语句时就可以可有可无.
hm616911 2007-10-19
  • 打赏
  • 举报
回复
楼上上
小呆之家 2007-10-19
  • 打赏
  • 举报
回复

//下面的代码结构就是一个单元的整体结构了。
unit UnitName;

interface
//这儿是接口部分

implementation
//这儿是实现部分

//这儿,你加一个begin,编译器会给你优化掉的。 嘻~~.....
end.//这个end是单元的结束了


//下面代码是DLL工程的结构,在这儿,就不能省略了。。。。。
library Project2;

{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }

uses
SysUtils,
Classes;

{$R *.res}

begin
end.




luxuewei5214 2007-10-19
  • 打赏
  • 举报
回复
上上上
brightyang 2007-10-18
  • 打赏
  • 举报
回复
楼上
hongqi162 2007-10-18
  • 打赏
  • 举报
回复
procedure TForm1.Button1Click(Sender: TObject);
begin
showMessage( 'OK ')
end;


showmessage后没有分号结尾也可以,编译器会帮你处理
hongqi162 2007-10-18
  • 打赏
  • 举报
回复
编译器自动就给你优化掉了

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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