Jump to content
Sign in to follow this  
andre_mz

[Dúvida] Delphi

Recommended Posts

andre_mz
Anatomy of a Delphi Unit

Delphi units must follow a predefined format. This shouldn't come as a surprise to you. The unit has to be in a predefined

format so that the compiler can read the unit and compile the unit's code.

A Delphi project unit contains the program keyword followed by the name of the unit and a code block marked by the begin

and end keywords. You can see how a basic unit looks by choosing View | Project Source from the Delphi main menu. The

project source unit for a default Delphi project looks like Listing 1.1.

NOTE: The line numbers in Listing 1.1 are not part of the unit itself. I have put them there for reference only.

Some of the listings you see in this book will have line numbers for reference and others will not. In either case,

be sure to understand that the Pascal language does not use line numbers as some other languages do (most

notably, BASIC).

LISTING 1.1. THE PROJECT SOURCE FOR A DEFAULT DELPHI PROJECT.

01: program Project1;

02:

03: uses

04: Forms,

05: Unit1 in `Unit1.pas' {Form1};

06:

07: {$R *.RES}

08:

09: begin

10: Application.Initialize;

11: Application.CreateForm(TForm1, Form1);

12: Application.Run;

13: end.

On line 1, the program keyword identifies this unit as a program's main source unit. You can see that the unit name, Project1,

follows the program keyword (Delphi gives the project a default name until you save the project with a more meaningful

name). Beginning on line 3, you see a section identified by the uses keyword. Any unit names following the uses keyword, up

to the semicolon, are other units that this unit requires in order to compile. The uses keyword is described in more detail a little

later in the section, "The uses List."

On line 7 you see a compiler directive that tells Delphi to include this project's resource file. Resource files are discussed in

more detail on Day 8, "Creating Applications in Delphi."

Line 9 contains the begin keyword, and line 13 contains the end keyword. Notice that the final end keyword in the unit is

followed by a period. (A unit can have many code blocks marked with begin and end, but only one final end statement.) The

code on lines 10, 11, and 12 is code that initializes the application, creates the application's main form, and starts the

application running. You don't need to be concerned about the details of this code to write Delphi programs.

NOTE: The begin and end keywords mark a code block. A code block can contain just a few lines of code, or it

can contain several hundred lines of code (or even thousands of lines). You will see the begin and end keywords

used throughout the book. As you work through the book, you will get a better handle on how and when the begin

and end keywords are used.

Ok, podem achar ridicula a minha dúvida ... xD

Isto é um ebook que ensina sobre Delphi.

Mas tipo, pelo que eu sei de inglês diz ai para "se ver" como uma unit predefinida é. E seria depois de fazer os passos que estão a bold, só que eu depois de "View", eu não encontro "Project Source from the Delphi main menu".

Pronto, eu gostava de saber, depois de se abrir o Delphi, onde é que se podem encontrar aqueles códigos ... eu não encontro "lugar" nenhum onde apareça "program Project1;".

Só encontro por exemplo ... "unit Unit1;"

Pronto, +- é que eu não consigo entrar no código do projecto, lol que baralhada, mas gostaria que me ajudassem nesta dúvida no mínimo estúpida e noob, obrigado.

=)

Share this post


Link to post
Share on other sites
marinheiro

é só "view/project source"... aí é que vais ver o "program project1;"


há 10 tipos de pessoas: as que sabem binário e as que não sabem...[br][br]todas as nossas vidas não passam de release candidates... com o aperfeiçoamento, um dia chegaremos à versão final..

Share this post


Link to post
Share on other sites
andre_mz

Desculpem o double post, mas a minha versão do Delphi é outra ... xD e já descobri em project > view source, obrigado na mesma pelas respostas =)))

EDIT

On line 7 you see a compiler directive that tells Delphi to include this project's resource file.

Alguém me poderia explicar o que significa isto? É que eu não estou a perceber muito bem.

Cumpz.

Obrigado =)

Share this post


Link to post
Share on other sites
marinheiro

os resource files são ficheiros onde são guardados recursos da aplicação (icon's, imagens, etc.) que são compilados para o exe (aumentano o seu tamanho, claro), em vez de serem ficheiros lidos externamente, sendo mais rápida a sua utilização. na versão que eu tenho aqui, podes encontrar em "view/project resources" e podes modificar ou acrescentar recursos...


há 10 tipos de pessoas: as que sabem binário e as que não sabem...[br][br]todas as nossas vidas não passam de release candidates... com o aperfeiçoamento, um dia chegaremos à versão final..

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.