Home arrow Support arrow Gurock Software Forum arrow General Discussion arrow No LogStringList for TWideStrings?

Subscribe to forum RSS Forum

No LogStringList for TWideStrings?

New Topic Post Reply

Page: 1

Author Post
Member
Registered: Apr 2008
Posts: 7
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.
Administrator
Registered: Sep 2007
Posts: 133
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.

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.
« Last edit by Tobias Gurock on Wed Apr 02, 2008 7:17 am. »
Member
Registered: Apr 2008
Posts: 7
Thanks very much
Administrator
Registered: Sep 2007
Posts: 133
You are welcome.

New Topic Post Reply

Page: 1