2013-07-05 107 views
2

我调试我的Delphi应用程序来获得许多数据库字段外键的值使用它们在调试存储过程的行为中所需要的所有字段值。该领域有这么多,所以我不知道是否有一个更快的方式来获得像填充所有的人到手表窗口,而不是写一个表达式,任何一个领域,我需要观察这些值。填充在监视窗口

换句话说,我需要看的所有字段值几个表。我不需要所有这些,但我可以很容易地从这样的列表中选择我需要的。

目前我正在写的手表表达这样的:

<data module>.<Table Component>.fieldbyname('Field_Name').asinteger 

回答

2

为此,我将字段转储到跟踪日志ei是这样的:

function IfThen(AValue: Boolean; const ATrue, AFalse: string): string; overload; 
begin 
    if AValue then 
    Result := ATrue 
    else 
    Result := AFalse; 
end; 

procedure LogDebugFields(ADat: TDataset; ADirection: string = ''); 
var 
    OwnerName: string; 
    Idx: integer; 
    Field: TField; 
begin 
    if not Assigned(ADat) or not (ADat is TDataset) then 
    exit; 
    if Assigned(ADat.Owner) then 
    OwnerName := ADat.Owner.Name + '_' 
    else 
    OwnerName := ''; 
    LogDebugStringFmt('Dump of dataset in the state "%s" with "%d" fields', 
     [DatasetStateToStr(ADat.State), ADat.Fields.Count], 
    OwnerName + ADat.Name, ADirection); 
    for Idx := 0 to ADat.Fields.Count - 1 do 
    begin 
    Field := ADat.Fields[Idx]; 
    LogDebugContinued(Format('[%2.2d] %-48.48s = %s', 
     [Idx, Format('%s (%s%s)', [Field.FieldName, Field.ClassName, 
      IfThen(Field.Required, ', NOT NULL)', '')]), Field.AsString])); 
    end; 
end; 
6

不是真的。有没有办法来循环建立的手表,或者以任何方式没有一些代码设置一次设置多个数据库字段的手表。

在Delphi 2010及更高版本中,您可以编写自己的debugger visualizer(请参阅External-Viewer Visualizers一节)为您提供自定义视图,但这将是一个相当广泛的任务。 (有一个在$(BDS)\Source\Visualizers文件夹中提供的样本;外部观察者是StringListViewer

您可以创建持久字段,以简化其添加到监视窗口(双击表格组件并选择Add Field...Add All Fields),和那么你可以参考它们作为datamodule.tablefield.AsInteger

或者,您可以分配领域分离的局部变量,然后就看着他们,而不是):

var 
    AField: TField; 
    AnotherField: TField; 
begin 
    AField := dm.TableA.FieldByName('FieldA'); 
    AnotherField := dm.TableA.FieldByName('FieldB'); 
    ... 
end; 

然后设置你的手表上,而不是AField.AsInteger,这将加快建立手表一点。

(对于非调试目的,声明局部TField变量和将它们设置在循环之前可以通过除去使用FieldByName字段的常数查找速度代码相当多。)

另一种可能性是声明并使用您在循环中指定的局部变量,然后您可以观察该局部变量:

var 
    FieldAValue: Integer; 
    FieldA: TField; 
begin 
    FieldA := dm.TableA.FieldByName('FieldA'); 
    while not dm.TableA.Eof do 
    begin 
    FieldAValue := FieldA.AsInteger; 
    // Use FieldAValue here instead of the Field.AsInteger, so the 
    // compiler doesn't eliminate it. You can add a watch by right-clicking 
    // FieldAValue and choosing Debug->Add watch at cursor or Ctrl+F5. 
    TableA.Next; 
    end; 
end; 
+0

感谢,即最后一个例子应该通过表字段不是行和也许我可以同时循环存储的字段/值对循环(如VAR iant)ini文件后我可以打开这个文件,并采取值...这对我来说是最合适的解决方案。 – Wel

0

,可以快速退出IDE和编辑中的.dsk文件[Watches]部分添加的手表到您的项目。

这里就是我想复制和修改的8只手表(Watch4..Watch11)块的例子:

以前

[Watches] 
Count=12 
Watch0='AEvent.getcustomfieldvaluebyname(splantaskfromdate)',256,0,18,1,1,'Watches',1 
Watch1='AEvent.getcustomfieldvaluebyname(splantasktodate)',256,0,18,1,1,'Watches',1 
Watch2='aevent.start',256,0,18,1,1,'Watches',1 
Watch3='aevent.finish',256,0,18,1,1,'Watches',1 
Watch4='FDMPPlan.FEvent1833.start',256,0,18,1,1,'Watches',1 
Watch5='FDMPPlan.FEvent1833.finish',256,0,18,1,1,'Watches',1 
Watch6='FDMPPlan.FEvent1833.getcustomfieldvaluebyname(''tt_fromdate'')',256,0,18,1,1,'Watches',1 
Watch7='FDMPPlan.FEvent1833.getcustomfieldvaluebyname(''tt_todate'')',256,0,18,1,1,'Watches',1 
Watch8='FEvent1833.start',256,0,18,1,1,'Watches',1 
Watch9='FEvent1833.finish',256,0,18,1,1,'Watches',1 
Watch10='FEvent1833.getcustomfieldvaluebyname(''tt_fromdate'')',256,0,18,1,1,'Watches',1 
Watch11='FEvent1833.getcustomfieldvaluebyname(''tt_todate'')',256,0,18,1,1,'Watches',1 

[Watches] 
Count=20 
Watch0='AEvent.getcustomfieldvaluebyname(splantaskfromdate)',256,0,18,1,1,'Watches',1 
Watch1='AEvent.getcustomfieldvaluebyname(splantasktodate)',256,0,18,1,1,'Watches',1 
Watch2='aevent.start',256,0,18,1,1,'Watches',1 
Watch3='aevent.finish',256,0,18,1,1,'Watches',1 
Watch4='FDMPPlan.FEvent1833.start',256,0,18,1,1,'Watches',1 
Watch5='FDMPPlan.FEvent1833.finish',256,0,18,1,1,'Watches',1 
Watch6='FDMPPlan.FEvent1833.getcustomfieldvaluebyname(''tt_fromdate'')',256,0,18,1,1,'Watches',1 
Watch7='FDMPPlan.FEvent1833.getcustomfieldvaluebyname(''tt_todate'')',256,0,18,1,1,'Watches',1 
Watch8='FEvent1833.start',256,0,18,1,1,'Watches',1 
Watch9='FEvent1833.finish',256,0,18,1,1,'Watches',1 
Watch10='FEvent1833.getcustomfieldvaluebyname(''tt_fromdate'')',256,0,18,1,1,'Watches',1 
Watch11='FEvent1833.getcustomfieldvaluebyname(''tt_todate'')',256,0,18,1,1,'Watches',1 
Watch12='FDMPPlan.FEvent1834.start',256,0,18,1,1,'Watches',1 
Watch13='FDMPPlan.FEvent1834.finish',256,0,18,1,1,'Watches',1 
Watch14='FDMPPlan.FEvent1834.getcustomfieldvaluebyname(''tt_fromdate'')',256,0,18,1,1,'Watches',1 
Watch15='FDMPPlan.FEvent1834.getcustomfieldvaluebyname(''tt_todate'')',256,0,18,1,1,'Watches',1 
Watch16='FEvent1834.start',256,0,18,1,1,'Watches',1 
Watch17='FEvent1834.finish',256,0,18,1,1,'Watches',1 
Watch18='FEvent1834.getcustomfieldvaluebyname(''tt_fromdate'')',256,0,18,1,1,'Watches',1 
Watch19='FEvent1834.getcustomfieldvaluebyname(''tt_todate'')',256,0,18,1,1,'Watches',1