Pesquisar neste blogue

quinta-feira, 9 de junho de 2011

Create a run-time object in Delphi.

Hello reader.
Anytime you have the necessity of associate 2 object events to just 1 method? Yes, maybe.
Right now I guide you, on how to solve the problem of use the same object that you're clicked(if you use the event onClick).
In this example I've got 2 buttons with the same event onClick. We go put the caption 'Button + aleatorial number'.
So, at the event onClick of the 2 Buttons put the code:
TButton(sender).Caption := 'Button ' + IntToStr(Random(255));
I wait that it be useful

3 comentários:

  1. Eu uso algo parecido para mudar a cor dos TEdits das minhas aplicações quando recebem foco:

    coloco no onEnter de UM Edit e uso o mesmo evento para todos os outros:
    TEdit(sender).color := clYellow;

    e no OnExit:
    TEdit(sender).color := clDefault;

    ResponderEliminar
  2. Tbutton.create(self)
    tbutton.name:=teste1;
    teste1.caption:= 'blablabla'

    isso resolve

    ResponderEliminar
  3. Não se o botão estiver criado em design, ou se tiver de ser criado com outro evento.

    ResponderEliminar

Obtigado pelo comentário.