Ir para conteúdo
Fórum Script Brasil
  • 0

Usar o This no delphi


danielrgoes

Pergunta

Boa tarde pessoal

eu programo em JAVA e Delphi

No JAVA eu tenho um comnado para falar do componente que estou utilizando (this)

gostaria de saber se o Delphi possue algo assim ou seja

eu estou no evento Click de um BitBtn por exemplo

para não utilizar o nome dele (BitBtn1.text := 'TESTE')

eu usaria o (this.text := 'TESTE')

muito obrigado

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0
No JAVA eu tenho um comnado para falar do componente que estou utilizando (this)

gostaria de saber se o Delphi possue algo assim

Existe sim é a senteça With

A with statement is a shorthand for referencing the fields of a record or the fields, properties, and methods of an object. The syntax of a with statement is

with obj do statement

or

with obj1, ..., objn do statement

where obj is a variable reference denoting an object or record, and statement is any simple or structured statement. Within statement, you can refer to fields, properties, and methods of obj using their identifiers alone—without qualifiers.

For example, given the declarations

type TDate = record

Day: Integer;

Month: Integer;

Year: Integer;

end;

var OrderDate: TDate;

you could write the following with statement.

with OrderDate do

if Month = 12 then

begin

Month := 1;

Year := Year + 1;

end

else

Month := Month + 1;

This is equivalent to

if OrderDate.Month = 12 then

begin

OrderDate.Month := 1;

OrderDate.Year := OrderDate.Year + 1;

end

else

OrderDate.Month := OrderDate.Month + 1;

If the interpretation of obj involves indexing arrays or dereferencing pointers, these actions are performed once, before statement is executed. This makes with statements efficient as well as concise. It also means that assignments to a variable within statement cannot affect the interpretation of obj during the current execution of the with statement.

Each variable reference or method name in a with statement is interpreted, if possible, as a member of the specified object or record. If there is another variable or method of the same name that you want to access from the with statement, you need to prepend it with a qualifier, as in the following example.

with OrderDate do

begin

Year := Unit1.Year

...

end;

When multiple objects or records appear after with, the entire statement is treated like a series of nested with statements. Thus

with obj1, obj2, ..., objn do statement

is equivalent to

with obj1 do

with obj2 do

...

with objn do

statement

In this case, each variable reference or method name in statement is interpreted, if possible, as a member of objn; otherwise it is interpreted, if possible, as a member of obj

n–1; and so forth. The same rule applies to interpreting the objs themselves, so that, for instance, if objn is a member of both obj1 and obj2, it is interpreted as obj2.objn.

abraço

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...