Fórum Criando Objetos conforme dados em Banco #397854
23/03/2011
0
Id da criança, Data de entrada, Hora de entrada. Quando fecha o tempo, grava data de saída, hora de saída, tempo utilizado, valor a pagar e registra que a tela está desocupada. Daí queria saber o seguinte, ao invez deu recriar os códigos para cada
tela, tipo, eu tenho 28 telas e utilizo 28 TTimers, 28 botões pra abrir e fechar tela. Queria tipo assim, uma tabela temporária, para cada registro nessa tabela, o sistema criar automaticamente um TTimer, o botão abre e fecha tempo. Exemplo: IdCrian 01 Timer01 btAbre01 btFecha01 ---------------------- IdCrian 02 Timer02 btAbre02 btFecha02 Ou seja, eu só irei escrever o código uma únicavez para criar os objetos com base nos dados na table temporária. Espero ter explicado corretamente minha idéia...
Paulo Andrade
Curtir tópico
+ 0Posts
23/03/2011
Gustavo Bretas
with TFormularioCriado.Create(Application) do try mtdCarregaInf(CodigoDaCriança); ShowModal; finally Free end;
Gostei + 0
23/03/2011
Paulo Andrade
with TFormularioCriado.Create(Application) do try mtdCarregaInf(CodigoDaCriança); ShowModal; finally Free end;
Gostei + 0
23/03/2011
Gustavo Bretas
unit untPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBClient, ComCtrls, ToolWin;
type
TfrmPrincipal = class(TForm)
Timer: TTimer;
btnAdicionar: TButton;
procedure btnAdicionarClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
nArrayButton : Array of Array of String;
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
uses DateUtils;
{$R *.dfm}
procedure TfrmPrincipal.btnAdicionarClick(Sender: TObject);
const
cSeparador : Integer = 4;
var
nLeft, nTop : Integer;
begin
if High(nArrayButton) < 0 then
begin
nLeft := 10;
nTop := 60;
SetLength(nArrayButton, 1);
SetLength(nArrayButton[0], 2);
end
else
begin
nLeft := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Left
+ TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Width + cSeparador;
nTop := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Top;
if TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Width + nLeft >= Self.Width then
begin
nLeft := 10;
nTop := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Top
+ TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Height + cSeparador;
end;
SetLength(nArrayButton, High(nArrayButton) + 2);
SetLength(nArrayButton[High(nArrayButton)], High(nArrayButton) + 1);
end;
with TButton.Create(Self) do
begin
Left := nLeft;
Top := nTop;
Parent := Self;
Name := 'btn'+ IntToStr(High(nArrayButton));
Caption := 'btn'+ IntToStr(High(nArrayButton));
nArrayButton[High(nArrayButton), 0] := Name;
nArrayButton[High(nArrayButton), 1] := FormatDateTime('dd/mm/yyyy hh:mm:ss', Now);
Application.ProcessMessages;
end;
end;
procedure TfrmPrincipal.TimerTimer(Sender: TObject);
var
i : Integer;
begin
for i := Low(nArrayButton) to High(nArrayButton) do
with TButton(Self.FindComponent(nArrayButton[i, 0])) do
begin
Caption := FormatDateTime('hh:mm:ss', Now - StrToDateTime(nArrayButton[i, 1]));
end;
end;
end.
Gostei + 0
24/03/2011
Paulo Andrade
unit untPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBClient, ComCtrls, ToolWin;
type
TfrmPrincipal = class(TForm)
Timer: TTimer;
btnAdicionar: TButton;
procedure btnAdicionarClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
nArrayButton : Array of Array of String;
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
uses DateUtils;
{$R *.dfm}
procedure TfrmPrincipal.btnAdicionarClick(Sender: TObject);
const
cSeparador : Integer = 4;
var
nLeft, nTop : Integer;
begin
if High(nArrayButton) < 0 then
begin
nLeft := 10;
nTop := 60;
SetLength(nArrayButton, 1);
SetLength(nArrayButton[0], 2);
end
else
begin
nLeft := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Left
+ TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Width + cSeparador;
nTop := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Top;
if TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Width + nLeft >= Self.Width then
begin
nLeft := 10;
nTop := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Top
+ TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Height + cSeparador;
end;
SetLength(nArrayButton, High(nArrayButton) + 2);
SetLength(nArrayButton[High(nArrayButton)], High(nArrayButton) + 1);
end;
with TButton.Create(Self) do
begin
Left := nLeft;
Top := nTop;
Parent := Self;
Name := 'btn'+ IntToStr(High(nArrayButton));
Caption := 'btn'+ IntToStr(High(nArrayButton));
nArrayButton[High(nArrayButton), 0] := Name;
nArrayButton[High(nArrayButton), 1] := FormatDateTime('dd/mm/yyyy hh:mm:ss', Now);
Application.ProcessMessages;
end;
end;
procedure TfrmPrincipal.TimerTimer(Sender: TObject);
var
i : Integer;
begin
for i := Low(nArrayButton) to High(nArrayButton) do
with TButton(Self.FindComponent(nArrayButton[i, 0])) do
begin
Caption := FormatDateTime('hh:mm:ss', Now - StrToDateTime(nArrayButton[i, 1]));
end;
end;
end.
Gostei + 0
24/03/2011
Paulo Andrade
unit untPrincipal;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls, DB, DBClient, ComCtrls, ToolWin;
type
TfrmPrincipal = class(TForm)
Timer: TTimer;
btnAdicionar: TButton;
procedure btnAdicionarClick(Sender: TObject);
procedure TimerTimer(Sender: TObject);
private
nArrayButton : Array of Array of String;
{ Private declarations }
public
{ Public declarations }
end;
var
frmPrincipal: TfrmPrincipal;
implementation
uses DateUtils;
{$R *.dfm}
procedure TfrmPrincipal.btnAdicionarClick(Sender: TObject);
const
cSeparador : Integer = 4;
var
nLeft, nTop : Integer;
begin
if High(nArrayButton) < 0 then
begin
nLeft := 10;
nTop := 60;
SetLength(nArrayButton, 1);
SetLength(nArrayButton[0], 2);
end
else
begin
nLeft := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Left
+ TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Width + cSeparador;
nTop := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Top;
if TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Width + nLeft >= Self.Width then
begin
nLeft := 10;
nTop := TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Top
+ TButton(Self.FindComponent('btn'+ IntToStr(High(nArrayButton)))).Height + cSeparador;
end;
SetLength(nArrayButton, High(nArrayButton) + 2);
SetLength(nArrayButton[High(nArrayButton)], High(nArrayButton) + 1);
end;
with TButton.Create(Self) do
begin
Left := nLeft;
Top := nTop;
Parent := Self;
Name := 'btn'+ IntToStr(High(nArrayButton));
Caption := 'btn'+ IntToStr(High(nArrayButton));
nArrayButton[High(nArrayButton), 0] := Name;
nArrayButton[High(nArrayButton), 1] := FormatDateTime('dd/mm/yyyy hh:mm:ss', Now);
Application.ProcessMessages;
end;
end;
procedure TfrmPrincipal.TimerTimer(Sender: TObject);
var
i : Integer;
begin
for i := Low(nArrayButton) to High(nArrayButton) do
with TButton(Self.FindComponent(nArrayButton[i, 0])) do
begin
Caption := FormatDateTime('hh:mm:ss', Now - StrToDateTime(nArrayButton[i, 1]));
end;
end;
end.
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)