Ayuda para crear una funcion o metodo

Tengo definido un documento que ingresa datos, para lo que he definido, varios edit, de manera que en el onexit del primero se debe evaluar un codigo, dependiendo de lo cual activa el sigiente edit o vuelve al mismo de origen.
Como esta operación debo repetirla para cada linea de ingreso de datos, quisiera usar un metodo o funcion que evite repetir esta operación en el onexit de cada edit.
He intentado lo siguiente, pero no me funciona, por lo que agradecere cualquier ayuda.
procedure TForm17.Edit8Exit(Sender: TObject);
begin
NumeroEdit:=8;
NumeroMask:=2;
correctoelcodigo(8,2);
end;
procedure correctoelcodigo;
begin
if messagedlg ('¿Correcto el codigo?',mtwarning,
[mbyes,mbno],0)=mryes then
begin
numeroedit:=numeroedit+1;
'edit'+inttostr(numeroedit).setfocus; //NO LO RECONOCE COMO EDIT9
end
else
'edit'+inttostr(NumeroMask).setfocus; //NO LO RECONOCE COMO EDIT8
end;
end;

1 respuesta

Respuesta
1
A ver que te parece esto:
unit Unit1;
Interface
Uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Edit2: TEdit;
Panel1: TPanel;
Edit3: TEdit;
procedure EditExit (Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TForm1 }
procedure TForm1.EditExit(Sender: TObject);
function GetEditxTag(wc : Twincontrol; ATag : Integer) : TEdit;
var
i : Integer;
begin
result := nil;
for i := 0 to wc.ComponentCount -1 do
begin
if wc.Components is TWinControl then
GetEditxTag(TWincontrol(wc.Components), ATag)
else
if wc.Components is TEdit then
if wc.Components.Tag = 0 then
begin
result := TEdit(wc.Components);
exit;
end;
end;
end;
var
esvalido : Boolean;
EditSiguiente : TEdit;
begin
//Evento OnExit personalizado
esvalido := false;
//Comprobamos que en cada edit entre lo que queramos, sino no le dejamos salir.
Case TEdit(sender).Tag of
1 : if TEdit(sender).Text <> 'linea1' then
showmessage('Entrada no correcta')
else esvalido := true;
2 : if TEdit(sender).Text <> 'linea2' then
showmessage('Entrada no correcta')
else esvalido := true;
3 : if TEdit(sender).Text <> 'linea3' then
showmessage('Entrada no correcta')
else esvalido := true;
end;
if not esvalido then
TEdit(sender).SetFocus
else
begin
EditSiguiente := GetEditxTag(self, TEdit(sender).Tag + 1);
if Assigned(EditSiguiente) then
EditSiguiente.SetFocus;
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
i : Integer;
begin
//Por ejemplo, usaremos el tag de los componentes para diferenciarlos de los otros.
for i := 0 to ComponentCount -1 do
if Components is TEdit then
if Components.Tag > 0 then
begin
TEdit(Components).Text := '';
TEdit(Components).OnExit := EditExit;
end;
end;
end.

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas