CnPack Forum » CnWizards IDE Wizards » How to get live object from IDE with OTA


2009-9-19 21:54 AntonioBakula
How to get live object from IDE with OTA

This question is not related to cnPack, so I apologise in advance for that, but I was thinking that maybe some of you know the answer :)

I am trying to make debugger Visualizer for Dataset classes for Delphi 2010, using build in StringListVisualizer as a reference, but I can't get
viewed object with IOTAThread.Evaluate, btw. StringListVisualizer gets content with eval as string.

I tried casting  value returned from Evaluate in ResultAddr to TDataset but that is not working, in variable Exppresion is dataset variable
name and EvalRes is returne as erOK, but when I try to use Result access violation occures.

Here is the code (this is a slightly modified code from StringList visualizer) :

function TDatasetViewerFrame.GetDataset(Expression: string): TDataset;
var
  CurProcess: IOTAProcess;
  CurThread: IOTAThread;
  ResultStr: array[0..4095] of Char;
  CanModify: Boolean;
  ResultAddr, ResultSize, ResultVal: LongWord;
  EvalRes: TOTAEvaluateResult;
  DebugSvcs: IOTADebuggerServices;
begin
  begin
    Result := nil;
    if Supports(BorlandIDEServices, IOTADebuggerServices, DebugSvcs) then
      CurProcess := DebugSvcs.CurrentProcess;

    if CurProcess <> nil then
    begin
      CurThread := CurProcess.CurrentThread;
      if CurThread <> nil then
      begin
        EvalRes := CurThread.Evaluate(Expression, @ResultStr, Length(ResultStr), CanModify, eseAll, '', ResultAddr, ResultSize, ResultVal,
'', 0);

        case EvalRes of
          erOK:
            Result := TDataset(ResultAddr);  // Result is shown as Inaccessible value in debugger

2009-9-20 10:29 Passion
Could you check the hex value of returned ResultAddr?

Or just check its classname using TObject(ResultAddr).ClassName,
If AV occured, indicate it's not an object, and not a Dataset object.

I'm afraid it's a string such as "([csInheritable])", like shown in Evaluation/Modify window when evaluating an object var in it.

2009-9-21 17:01 AntonioBakula
Hi Passion !

In Expression variable i have name of an live object (eg. "AdoDataset1") not "([csInheritable])"

Hex value of ResultAddr is $13A46AC

I tried to chek class name of casted pointer but AV occurred, in embarcadero.public.delphi.opentoolsapi I've got an answer that this is not possible because the object's address is in a different virtual address space, to bad :(

So it seems that is not possible to make visualizer for TDataset classes, anyway thanks for your time

2009-9-21 18:05 AntonioBakula
I find workaround, but unfortunatly it will work only for dataset that have SaveToFile method, I will evaluate expression (here is the name of dataset variable) + 'SaveToFile('sometempfile')'

this works for TClientDataset

2009-9-21 19:47 Passion
Oh yes. They're not in same process. We can only obtain needed values using whole expression with properties, such as StringList1.Text to get the simple value. Not the object itself.:)

2009-9-22 15:52 AntonioBakula
This makes Debug Visualizers pretty limited, I hope that next OTA version will have this possibility

页: [1]


Powered by Discuz! Archiver 5.0.0  © 2001-2006 Comsenz Inc.