Recent

Author Topic: ShowMess(age) with array of const  (Read 939 times)

winni

  • Hero Member
  • *****
  • Posts: 3197
ShowMess(age) with array of const
« on: October 31, 2019, 11:12:03 pm »
Hi!

Often enough you insert just a showmessage in your code to inspect the values of your variables. Before you have a look at the debugger or the debug log or breakpoints.

A lot of typing is needed to convert all this variables to strings for showmessage. And then you found the bug and delete it all. So what about a showmessage with an Array of Const as parameter? I just did it and called it "showmess" : it should show my mess .....


Code: Pascal  [Select][+][-]
  1. uses
  2.   Classes, SysUtils, Forms, LCLType;
  3.  
  4. .....
  5.  
  6.  
  7. Procedure ShowMess (params: Array of const);
  8. const vtStrings : array[0..18] of string = (
  9.       'Integer', 'Boolean', 'Char', 'Extended', 'ShortString', 'Pointer', 'PChar',
  10.       'Object', 'Class', 'WideChar', 'PWideChar','AnsiString', 'Currency','Variant',
  11.       'Interface','WideString','Int64','QWord','UnicodeString');
  12.  
  13. Var i : integer;
  14.     s : string = '';
  15. begin
  16.   For i:=0 to High(params) do
  17.     begin
  18.     s := s + vtStrings [params[i].vtype]+': ';
  19.              case params[i].vtype of
  20.                vtinteger    : s := s + IntToStr(params[i].vinteger) ;
  21.                vtboolean    : s := s + BoolToStr(params[i].vboolean,true);
  22.                vtchar       : s := s + params[i].vchar ;
  23.                vtextended   : s := s + FloatToStr(params[i].VExtended^);
  24.                vtString     : s := s + params[i].VString^;
  25.                vtPointer    : s := s + IntToStr(Longint(params[i].VPointer)) ;
  26.                vtPChar      : s := s + params[i].VPChar;
  27.                vtObject     : s := s + params[i].VObject.Classname;
  28.                vtClass      : s := s + params[i].VClass.Classname ;
  29.                vtWideChar   : s := s + params[i].VWideChar;
  30.                vtAnsiString : s := s + AnsiString(params[i].VAnsiString);
  31.                vtWideString : s := s + WideString(params[i].VWideString);
  32.                vtInt64      : s := s + IntToStr(params[i].VInt64^);
  33.                vtQWord      : s := s + IntToStr(params[i].VQWord^);
  34.                vtUnicodeString :
  35.                               s := s + UnicodeString(params[i].VUnicodeString);
  36.              otherwise
  37.                  s := s + ' Type '+IntToStr(params[i].vtype) + '  !Implement me! ';
  38.              end; // case
  39.     s := s + LineEnding;
  40.     end; // i
  41.     application.messagebox(pchar(s),'ShowMess', MB_ICONINFORMATION );
  42. end;
  43.  
  44.  

And you can call it with a lot of different types of parameters:


Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var P : TPoint;
  3.     img : TImage;
  4. begin
  5.   P := Point (10,5);
  6.   img := TImage.Create(Nil);
  7.   ShowMess([HasHelp, cmWhiteness,LCLVersion, high( int64 ), GetTickCount64 ,
  8.             MAXBYTE, '⚽', P.x, pi, img, MB_ICONINFORMATION ]);
  9.   img.free;
  10. end;
  11.  

Info 1: The input is restricted to "simple types", so you cannot use  record types like TPoint or TRect - pass them with their members (Rect.Top).

Info 2: All Integer Types  <= LongInt are shown as "Integer". All float types are shown as "Extended".

Screenshot of the messagebox is attached.


jamie

  • Hero Member
  • *****
  • Posts: 6130
Re: ShowMess(age) with array of const
« Reply #1 on: November 01, 2019, 12:19:54 am »
Please don't suggest more larded code in the libs, it's bad enough now..

Do as I do and make a personal unit with all your needed features that fits your needs..

Now if you had something to fix or a small change to produce a lot of value then I would love to see it.

 I believe in lean and mean and the use of release verses debug intrinsic compile conditioning code.


The only true wisdom is knowing you know nothing

 

TinyPortal © 2005-2018