Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
prog:lazarus:debug:lazlogger [07/04/2020 11:40] thierry créée |
prog:lazarus:debug:lazlogger [07/04/2020 12:35] (Version actuelle) thierry [DebugLn / DebugLnEnter / DebugLnExit] |
||
---|---|---|---|
Ligne 3: | Ligne 3: | ||
===== Les procedures ===== | ===== Les procedures ===== | ||
==== DebugLn / DebugLnEnter / DebugLnExit ==== | ==== DebugLn / DebugLnEnter / DebugLnExit ==== | ||
+ | <code delphi> | ||
+ | DebugLn(String); | ||
+ | DebugLn(String, Args); | ||
+ | </code> | ||
==== DbgOut ==== | ==== DbgOut ==== | ||
===== Interception d'un DebugLn ===== | ===== Interception d'un DebugLn ===== | ||
Il peut être utile d'intercepter la procédure ''DebugLn'' pour l'afficher au sein de l'application | Il peut être utile d'intercepter la procédure ''DebugLn'' pour l'afficher au sein de l'application | ||
- | <code delphi> | + | - Ligne 10 : On déclare une procedure de type ''TLazLoggerWriteEvent = procedure(Sender: TObject; S: string; var Handled: Boolean) of object;'' (''ReceptDebugLn'' dans l'exemple ci-dessous) |
+ | - Ligne 20 : On defini la property ''DebugLogger.OnDebugLn'' vers la procédure créé ci-dessus | ||
+ | - Ligne 25 : On a accés au log contenu dans la variable ''S'' | ||
+ | <code delphi [enable_line_numbers="true"]> | ||
+ | uses | ||
+ | ..., lazlogger, ... | ||
+ | type | ||
TForm1 = class(TForm) | TForm1 = class(TForm) | ||
- | GBContenor: TGroupBox; | + | ... |
- | FHEdit: TTIC_HexEditor; | + | MMDbg: TMemo; // Le TMemo qui recevra les logs |
- | GroupBox1: TGroupBox; | + | ... |
- | MMDbg: TMemo; | + | |
- | SynEdit1: TSynEdit; | + | |
procedure FormCreate(Sender: TObject); | procedure FormCreate(Sender: TObject); | ||
private | private | ||
- | procedure ReceptDebugLn(Sender: TObject; S: string; var Handled: Boolean); | + | procedure ReceptDebugLn(Sender: TObject; S: string; var Handled: Boolean); // La procedure d'interception |
public | public | ||
- | + | ... | |
end; | end; | ||
- | |||
var | var | ||
Form1: TForm1; | Form1: TForm1; | ||
- | |||
implementation | implementation | ||
- | |||
- | {$R *.lfm} | ||
- | |||
{ TForm1 } | { TForm1 } | ||
- | |||
procedure TForm1.FormCreate(Sender: TObject); | procedure TForm1.FormCreate(Sender: TObject); | ||
begin | begin | ||
- | FHEdit:=TTIC_HexEditor.create(self); | ||
- | FHEdit.parent:=GBContenor; | ||
- | FHEdit.Align:=alClient; | ||
DebugLogger.OnDebugLn:=@ReceptDebugLn; | DebugLogger.OnDebugLn:=@ReceptDebugLn; | ||
end; | end; | ||
- | procedure TForm1.ReceptDebugLn(Sender: TObject; S: string; var Handled: Boolean | + | procedure TForm1.ReceptDebugLn(Sender: TObject; S: string; var Handled: Boolean); |
- | ); | + | |
begin | begin | ||
MMDbg.Lines.Add(S); | MMDbg.Lines.Add(S); | ||
end; | end; | ||
- | |||
- | |||
</code> | </code> | ||
===== Sources ===== | ===== Sources ===== |