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 .....
uses
Classes, SysUtils, Forms, LCLType;
.....
Procedure ShowMess (params: Array of const);
const vtStrings : array[0..18] of string = (
'Integer', 'Boolean', 'Char', 'Extended', 'ShortString', 'Pointer', 'PChar',
'Object', 'Class', 'WideChar', 'PWideChar','AnsiString', 'Currency','Variant',
'Interface','WideString','Int64','QWord','UnicodeString');
Var i : integer;
s : string = '';
begin
For i:=0 to High(params) do
begin
s := s + vtStrings [params[i].vtype]+': ';
case params[i].vtype of
vtinteger : s := s + IntToStr(params[i].vinteger) ;
vtboolean : s := s + BoolToStr(params[i].vboolean,true);
vtchar : s := s + params[i].vchar ;
vtextended : s := s + FloatToStr(params[i].VExtended^);
vtString : s := s + params[i].VString^;
vtPointer : s := s + IntToStr(Longint(params[i].VPointer)) ;
vtPChar : s := s + params[i].VPChar;
vtObject : s := s + params[i].VObject.Classname;
vtClass : s := s + params[i].VClass.Classname ;
vtWideChar : s := s + params[i].VWideChar;
vtAnsiString : s := s + AnsiString(params[i].VAnsiString);
vtWideString : s := s + WideString(params[i].VWideString);
vtInt64 : s := s + IntToStr(params[i].VInt64^);
vtQWord : s := s + IntToStr(params[i].VQWord^);
vtUnicodeString :
s := s + UnicodeString(params[i].VUnicodeString);
otherwise
s := s + ' Type '+IntToStr(params[i].vtype) + ' !Implement me! ';
end; // case
s := s + LineEnding;
end; // i
application.messagebox(pchar(s),'ShowMess', MB_ICONINFORMATION );
end;
And you can call it with a lot of different types of parameters:
procedure TForm1.Button1Click(Sender: TObject);
var P : TPoint;
img : TImage;
begin
P := Point (10,5);
img := TImage.Create(Nil);
ShowMess([HasHelp, cmWhiteness,LCLVersion, high( int64 ), GetTickCount64 ,
MAXBYTE, '⚽', P.x, pi, img, MB_ICONINFORMATION ]);
img.free;
end;
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.