1 (edited by jrga 2023-10-16 14:46:36)

Topic: my solution to debug errors

This is my solution to help with debugging errors. If anyone can improve this idea or offer better alternatives, I would appreciate it.


procedure m(txt: variant; v: integer);
//*** minha solução para depurar...
begin
   if v = 1 then
       showmessage(vartostr(txt));
end;

Examples:

a = 1;
b = 'one';

displays message
m(a,1) 
m(b,1) 

or keep it in the code to display if necessary:

m(a,0);
m(b,0);
Roberto Alencar

2 (edited by brian.zaballa 2023-10-16 16:35:11)

Re: my solution to debug errors

im using a similar procedure to this one.

procedure sm(aMsg: Variant);
begin
    ShowMessage(VarToStr(aMsg));
end;

sm(1);
sm('two');

i'm curios to what will be the use case of v: integer.
are you perhaps want to disable the message before deploying your application?
if so, I would rather comment the line, than looking for all my uses of the procedure

begin
    // ShowMessage(VarToStr(aMsg));

or if you want to keep the test, then why not just comment the line of the test.

sm(1);
// sm('two');
brian

Re: my solution to debug errors

Hi brian.zaballa, putting // is also a good alternative. Thanks for the feedback

Roberto Alencar

4 (edited by brian.zaballa 2023-10-16 16:36:03)

Re: my solution to debug errors

but if you really want to have the minimal keyboard interaction when changing the uses, then i'm thinking something like this

procedure m(aMsg: Variant);
begin
    ShowMessage(VarToStr(aMsg));
end;
procedure xm(aMsg: Variant);
begin
    // do nothing
end;

m(1);
m('two');

xm(1);
xm('two');

adding/removing x before the test will just take 1 keystroke from your keyboard. rather than delete, then typing 1 or 0.

brian

Re: my solution to debug errors

It's also a good option and you understand my intention to interact with the keyboard as little as possible...

Roberto Alencar

6 (edited by jrga 2023-10-22 01:17:04)

Re: my solution to debug errors

other..

var
   mydebug: boolean = true; // false disable all breakpoints

procedure m(lbl:string;txt: variant);
//*** Proc 851 - minha solução para depurar...
begin
   if mydebug then
       showmessage(lbl + vartostr(txt));
end;

examples:

m('Edit1: ',frmLogin.Memo_tp2.text);
m('sKey: ',sKey);
Roberto Alencar