Page 1 of 1

DBMonitor is killing me!

Posted: Fri 10 Dec 2010 02:37
by sir.wally.lewis
I recently purchased UniDAC and am using it.
However during debugging DBMonitor moves my debug position.
I am NOT using DBMonitor but it is still active.

I cannot debug this way!

( I uses Delphi XE unidac 3.50 with source code )

How can I kill DBMonitor so It does not upset my debugging! :evil:

Posted: Fri 10 Dec 2010 12:12
by AlexP
Hello,

To resolve the problem you should set the TUniSQLMonitor.Active property to false.

Posted: Mon 13 Dec 2010 03:59
by sir.wally.lewis
I have no object instantiated of class TSQLMonitor.
So how can I set this non object to true!

Posted: Mon 13 Dec 2010 04:39
by sir.wally.lewis
ok i have worked around this, by adding the following code:

( I should not have had to do this! )


uses DBMonitorClient;

TUniConnection.AfterConnect := AfterV2Connect;

procedure TUniConnection.AfterV2Connect(Sender: TObject);
var
Mon : TDBMonitor;

begin
Mon := GetDBMonitor;
if( Assigned(Mon))then
Mon.Finish;
end;

Posted: Mon 13 Dec 2010 10:55
by AndreyZ
It seems that you create DBMonitor somewhere in your project. Please check it by adding a breakpoint in the TDBMonitor.Create constructor. Also note that the GetDBMonitor function creates TDBMonitor if it wasn't created earlier.

Posted: Mon 13 Dec 2010 22:42
by sir.wally.lewis
OK,

I have found that I have a class, which I instantiate.
However this class contains ACTIVE := FALSE. in its create sequence.

The below code in "UniSQLMonitor.pas" has been my downfall.
This code automatically instantiates it's own object. A move I had
not countered on. Which renders my ACTIVE := FALSE statement impotent.

I have also attached the class I created based on TUniSQLMonitor.
I can see I needed to descend it from TCustomDASQLMonitor instead and
set my options to [moDialog, moSQLMonitor, moCustom];



var
UniMonitor: TUniSQLMonitor;

{ TUniSQLMonitor }

constructor TUniSQLMonitor.Create(AOwner: TComponent);
begin
inherited Create(AOwner);

if UniMonitor = nil then
UniMonitor := Self;
end;


The class I created in my code is this:


TV2Monitor = class( TUniSQLMonitor )
private
slSQL : TStringList;
FMaxTrace : Integer;
function GetMonitorEnabled: Boolean;
procedure SetMonitorEnabled(const Value: Boolean);
function GetMaxTrace: Integer;
procedure SetMaxTrace(const Value: Integer);
procedure AddToList(Sender: TObject; Text: string; Flag: TDATraceFlag);
public
property MonitorEnabled:Boolean read GetMonitorEnabled write SetMonitorEnabled;
property MaxTrace : Integer read GetMaxTrace write SetMaxTrace default 10000;
constructor Create(AOwner: TComponent); override;
destructor Destroy;override;
procedure SaveToFile( FileName : String );
end;

{ TV2Monitor }

procedure TV2Monitor.AddToList(Sender: TObject; Text: string; Flag: TDATraceFlag);
var
slText : TStringList;
begin
slSQL.Add( FormatDateTime('YYYYMMDDHHNNSSZZZ', Now ));
slText := TStringList.Create;
slText.Text := Text;
slSQL.AddStrings(slText);
FreeAndNil(slText);
while( slSQL.Count > FMaxTrace )do
slSQL.Delete(0);
end;

constructor TV2Monitor.Create(AOwner: TComponent);
begin
inherited;
slSQL := TStringList.Create;
OnSQL := AddToList;
Active := FALSE;
end;

destructor TV2Monitor.Destroy;
begin
FreeAndNIl( slSQL );
inherited;
end;

function TV2Monitor.GetMaxTrace: Integer;
begin
Result := FMaxTrace;
end;

function TV2Monitor.GetMonitorEnabled: Boolean;
begin
Result := Active;
end;

procedure TV2Monitor.SaveToFile(FileName: String);
begin
slSQL.SaveToFile( FileName );
end;

procedure TV2Monitor.SetMaxTrace(const Value: Integer);
begin
FMaxTrace := Value;
end;

procedure TV2Monitor.SetMonitorEnabled(const Value: Boolean);
begin
Active := Value;
end;

Kind Regards,

Robert.
:idea:

Posted: Wed 15 Dec 2010 15:34
by bork
Hello

We will add the NeedAutoActivate function in the protected section of TCustomDASQLMonitor:

Code: Select all

function TCustomDASQLMonitor.NeedAutoActivate: boolean;
begin
  Result := (csDesigning in ComponentState) or
            (Owner = nil) or
            not (csReading in Owner.ComponentState);
end;
and modify the constructor of TCustomDASQLMonitor:

Code: Select all

constructor TCustomDASQLMonitor.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);

  FActive := False;
  FOptions := [moDialog, moSQLMonitor, moDBMonitor, moCustom];
  FTraceFlags := [tfQPrepare, tfQExecute, tfError, tfConnect, tfTransact, tfParams, tfMisc];
  FStreamedActive := True;
  FDBMonitorOptions := TDBMonitorOptions.Create;
  if NeedAutoActivate then
    Active := true;
end;
When you create your class that is inherited from TCustomDASQLMonitor (or TuniSQLMonitor), then you can override the NeedAutoActivate function and define the behavior of DBMonitor on creation.

These changes will be included in the next UniDAC build. If you have source code, you can add these changes manually.