Join 34,000+ subscribers and receive articles from our blog about software quality, testing, QA and security.
 

No LogStringList for TWideStrings?


#1

I just upgraded to v2 primarily for Unicode support and was surprised to see there is no LogStringList for TWideStrings. It’s not clear to me how I would even make my own method. If I just copy the code from the existing LogStringList, the call to SendContext is not possible since that is a private method.


#2

Hello Steve,

Thanks for upgrading and your posting. You are right, an overloaded LogStringList method for TWideStrings is missing, primarily because of old Delphi versions which do not have support for this type. I added it to our feature request list. In the meantime, you could add your own method to the TSiSession class. Beginning with Delphi 2006 (I think), Delphi supports the feature of class helper which lets you easily extend existing classes. Please see below for a detailed example on how to add a new LogWideStrings method which logs a TWideStrings object.

[code]program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils, SiAuto, SmartInspect, Classes, WideStrings;

type
TSiSessionHelper = class helper for TSiSession
public
procedure LogWideStrings(const ATitle: WideString;
const AWideStrings: TWideStrings); overload;
procedure LogWideStrings(const ALevel: TSiLevel; const ATitle: WideString;
const AWideStrings: TWideStrings); overload;
end;

{ TSiSessionHelper }

procedure TSiSessionHelper.LogWideStrings(const ALevel: TSiLevel;
const ATitle: WideString; const AWideStrings: TWideStrings);
var
I: Integer;
LContext: TSiListViewerContext;
begin
if not IsOn(ALevel) then
begin
Exit;
end;
if not Assigned(AWideStrings) then
begin
LogError(‘LogWideStrings: AWideStrings is not assigned’);
Exit;
end;
LContext := TSiListViewerContext.Create;
try
for I := 0 to AWideStrings.Count - 1 do
begin
LContext.AppendLine(AWideStrings[I]);
end;
LogCustomContext(ATitle, ltText, LContext);
finally
LContext.Free;
end;
end;

procedure TSiSessionHelper.LogWideStrings(const ATitle: WideString;
const AWideStrings: TWideStrings);
begin
LogWideStrings(Parent.DefaultLevel, ATitle, AWideStrings);
end;

var
LStrings: TWideStrings;
begin
LStrings := TWideStringList.Create;
try
LStrings.Add(‘This’);
LStrings.Add(‘is’);
LStrings.Add(‘a’);
LStrings.Add(‘TWideStrings’);
LStrings.Add(‘test’);
Si.Enabled := True;
SiMain.LogWideStrings(‘Test’, LStrings);
finally
LStrings.Free;
end;
end.
[/code]


#3

Thanks very much


#4

You are welcome.