这个"begin"为什么可有可无?解决方案
这个"begin"为什么可有可无?
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.
大侠们给讲解一下,谢谢!
------解决方案--------------------
编译器自动就给你优化掉了
------解决方案--------------------
楼上
------解决方案--------------------
楼上上
------解决方案--------------------
上上上
------解决方案--------------------
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.
大侠们给讲解一下,谢谢!
------解决方案--------------------
编译器自动就给你优化掉了
------解决方案--------------------
楼上
------解决方案--------------------
楼上上
------解决方案--------------------
上上上
------解决方案--------------------
- Delphi(Pascal) code
//下面的代码结构就是一个单元的整体结构了。 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.
------解决方案--------------------
begin和end相当于{},没有复合语句时就可以可有可无.
------解决方案--------------------
呵呵,晕死,大家都不太对的吧。你写上这个begin就会带来问题的:
一个单元是可以有一个initialization节和一个finalization节的,如果你写上了那个begin,你就不能再拥有initialization节(编译都不会通过),而如果没有initialization节,自然也就不能再有finalization节。
------解决方案--------------------
,,,学习,,
------解决方案--------------------
订
------解决方案--------------------
hongqi162
说得对。