Ver Mensaje Individual
  #11  
Antiguo 19-08-2005
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Reputación: 29
Lepe Va por buen camino
Gracias Roman, Yo el depurador no lo uso mucho, F7, F8, raton con hint, y poco más, no suelo usar breakpoints condicionales, ni watch.

La unidad no es cosa compleja, he usado un label de la JVCL, no sé por qué, puedes usar tambien un Label normal.

Tambien uso las nkstrs, para las funciones padright y padleft, se puede usar StringOfchar para obtener el mismo resultado, pero como las uso desde hace tiempo, las tengo siempre más a mano que las de delphi.

Yo al memo le tengo puesto la fuente Courier New, por aquello de fuente No proporcional.

Quizás la más interesante sea la de VerResultadosSql, ahorra mucho tiempo el no tener que poner un grid para ver si la consulta va bien o no. De hecho, junto con padright, padleft y la fuente Courier New va de lujo.

Código Delphi [-]
unit Debug;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls,
  db, dbtables, ComCtrls, ToolWin, JvLabel ; // datamoduletables

type
  TfrmDebug = class(TForm)
    Memo1: TMemo;
    ToolBar1: TToolBar;
    ToolButton1: TToolButton;
    ToolButton2: TToolButton;
    ToolButton3: TToolButton;
    ToolButton4: TToolButton;
    ToolButton5: TToolButton;
    ToolButton6: TToolButton;
    ToolButton7: TToolButton;
    SaveDialog1: TSaveDialog;
    ToolButton8: TToolButton;
    lblLineas: TJvLabel;
    CheckBox1: TCheckBox;
    procedure ToolButton1Click(Sender: TObject);
    procedure ToolButton2Click(Sender: TObject);
    procedure ToolButton3Click(Sender: TObject);
    procedure ToolButton5Click(Sender: TObject);
    procedure CheckBox1Click(Sender: TObject);
  private



    { Private declarations }
  public
    { Public declarations }
    procedure Anade(const Msg:array of string; const valores:array of Integer);overload;
    procedure AnadeCur(const Msg:array of string; const valores:array of Currency);    
    procedure Anade(str:string);overload;
    procedure Anade(str:TStrings); overload;
    procedure Anade(INT:Integer);overload;
    procedure ListaFrm;
    procedure ListaVentanasHijas(aFrm: Tform);
    procedure VerSentenciaSql(dt: TQuery);
    procedure VerResultadoSql(dt:TDataSet);
  end;

var
  frmDebug: TfrmDebug;

implementation
  USES nkstrs;
{$R *.dfm}

{ TfrmDebug }



procedure tfrmdebug.VerSentenciaSql(dt:TQuery);
begin
  frmDebug.Anade(dt.SQL.text);
end;

procedure TfrmDebug.AnadeCur(const Msg:array of string; const valores:array of Currency);
var i:Integer;
begin
  for i:= Low(Msg) TO High(Msg) do
    Memo1.Lines.Add(Msg[i]+': '+ CurrToStr(valores[i]));
  Update;
  lblLineas.Caption:= 'Lineas: '+CurrToStr(Memo1.Lines.Count);
  if not frmDebug.Showing then
    frmDebug.SHOW;
end;


procedure TfrmDebug.Anade(const Msg:array of string; const valores:array of Integer);
var i:Integer;
begin
  for i:= Low(Msg) TO High(Msg) do
    Memo1.Lines.Add(Msg[i]+': '+ IntToStr(valores[i]));
  Update;
  lblLineas.Caption:= 'Lineas: '+IntToStr(Memo1.Lines.Count);
  if not frmDebug.Showing then
    frmDebug.SHOW;
end;

procedure TfrmDebug.Anade(str: string);
begin
  Memo1.Lines.Add(str);
  lblLineas.Caption:= 'Lineas: '+IntToStr(Memo1.Lines.Count);
  if not frmDebug.Showing then
    frmDebug.Show;
end;


procedure TfrmDebug.Anade(INT : integer);
begin
  Memo1.Lines.Add(IntToStr(INT));
  lblLineas.Caption:= 'Lineas: '+IntToStr(Memo1.Lines.Count);
  if not frmDebug.Showing then
    frmDebug.Show;
end;

procedure TfrmDebug.Anade(str:TStrings);
var i:Integer;
begin
  for i:=0 to str.Count-1 do
    frmDebug.Anade(str[i]);

end;

procedure TfrmDebug.ListaVentanasHijas(aFrm:Tform);
var i:Integer;
begin
  frmdebug.anade('');
  anade('*** LISTADO DE VENTANAS (MdiChildren)***');
  for i:=0 to afrm.mdichildcount -1 do
    anade(afrm.mdichildren[i].Name);
  anade(['nº de hijas'],[aFrm.mdichildcount]);

end;


procedure tfrmdebug.ListaFrm();
const TABULADOR = '      ';
Var i:Integer;
Begin
    Memo1.Lines.BeginUpdate;
    memo1.Lines.Add('*** LISTADO DE VENTANAS (TScreen)***');
    For i:=0 to Screen.FormCount-1 do
    Begin
        MEMO1.Lines.Add(padright('Name: '+TForm(Screen.Forms[i]).Name,' ',30)+
        'Clase: '+ Screen.Forms[i].ClassName);
   end; //For i
    Memo1.Lines.Add('nº de ventanas: ' + IntToStr(Screen.FormCount));
    memo1.Lines.Add('***************************');
   Memo1.Lines.EndUpdate;
  lblLineas.Caption:= 'Lineas: '+IntToStr(Memo1.Lines.Count);
  if not frmDebug.Showing then
    frmDebug.Show;

end;

procedure TfrmDebug.VerResultadoSql(dt: TDataSet);
var i:Integer;
    campos :string;
begin
  if dt.Active then
  begin
//    campos := '';
    for i:= 0 to dt.FieldCount-1 do //Nombres de campos
      campos := campos+' ' + padright(dt.Fields[i].FullName,' ',dt.Fields[i].DisplayWidth);
    frmDebug.Anade(campos);
    frmDebug.Anade(PadLeft('','-',Length(campos)));
    dt.First;
    while not dt.Eof do  // valores de la consulta
    begin
      campos := '';
      for i:=0 to dt.FieldCount -1 do
        campos := campos+' ' + padright(dt.Fields[i].AsString,' ',dt.Fields[i].DisplayWidth);
      frmDebug.Anade(campos);
      dt.Next;
    end;
  end;
end;

Un saludo
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita