Find in Files" through Dephi's source code folders (and your project's folder if it's one of yours) to identify where the "undeclared" or missing item is declared.

问题描述 投票:0回答:1
Update

So, you've got this code, which I'll assume is in your uForm4.Pas unit.

You want to be able to do something with the Name value that's shown in the current row ofDBGrid1 on Form1. There's nothing particularly wrong with the way you've done it, just thatit's long-winded, error-prone and invites problems like the one you've having withTBookMark.

procedure TForm4.FormCreate(Sender: TObject);
var test : string;
var selectedRow, rows : TBookmark;
begin
  rows := Form1.DBGrid1.DataSource.DataSet.GetBookmark;
  Form1.DBGrid1.SelectedRows.CurrentRowSelected := True;
  Form1.DBGrid1.DataSource.DataSet.GotoBookmark(rows);
  test := Form1.DBGrid1.DataSource.DataSet.FieldByName('name').AsString;
  ShowMessage(test);

end;

end.
The point is that
delphi vcl firedac
1个回答
2
投票

property of Form1's DataSource1. For the sake of argument, lets'say that the dataset component is FDQuery1 on Form1 and you want to get the Name field valuefrom the current row in DBGrid1.

To get that Name value, you don't actually need the bookmarks your code is using. The waya TDBGrid works, the currently-selected row in the grid is always the current row in thedataset component. So you could simply write

because you don't need to go through the rigmarole of

to get to it.Now, to explain another little mystery, how come your code would work fine if it was in uForm1.Pasbut you get the

  procedure TForm4.FormCreate(Sender: TObject);
  var
    test : string;
  var
    selectedRow, rows : TBookmark;
  begin
    rows := Form1.DBGrid1.DataSource.DataSet.GetBookmark;
    Form1.DBGrid1.SelectedRows.CurrentRowSelected := True;
    Form1.DBGrid1.DataSource.DataSet.GotoBookmark(rows);
    test := Form1.DBGrid1.DataSource.DataSet.FieldByName('name').AsString;
    ShowMessage(test);
  end;

error why you try the same code in uForm4.Pasunit? Well, if you've ever watched the top of a source code file as it's being saved, you'll notice thatDelphi automatically adds, to the Uses list at the top, the units which contain any of thecomponents you've added to the form since its last save. So adding a TDataSource to the form would addthe DB unit to the Uses list, because that's where TDataSource is declared and so is TBookMark. Whichis why Delphi could compile Form1's code without the error, whereas when you try to mention a TBookMarkto uForm4, you need to add it to the unit's Uses list

unless you add a component (like TDataSource)to Form4 which will cause it to automatically add DB to the Uses list if it isn't already there. Mysterysolved. E2003 未声明标识符 "TBookmark DataSet嘿,我想在我的表格中使用TBookmark作为一个变量。我得到了它在另一个表格中运行,它的工作有。

但在新的形式,我得到的错误。我想我必须包括在使用声明的东西,但我不记得它是什么。下面是代码TBookmark是用红色下划线,所以这就是错误的地方。

    procedure TForm4.FormCreate(Sender: TObject);
    var
      test : string;
    begin
      test := Form1.FDQuery1.FieldByName('name').AsString;
      ShowMessage(test);
    end;

嘿,我想在我的表格中使用TBookmark作为一个varialbe。我得到了它在另一个表格中运行,它是工作有。但在新的形式,我得到的错误。我想我必须包括一些在...Form1.DBGrid1.DataSource.DataSet你的Form4需要使用DB单元,因为那是TBookMark被声明的地方。

顺便说一下,Form1单元中的内容与此无关。 唯一相关的是Form4的单元是 Undeclared Identifier: TBookMark 来使用DB.Pas单元。 发生的情况是,当编译器试图编译你的Form4单元时,它需要能够找到TBookMark的定义,而这是在标准的DB.Pas单元中,以及许多其他数据集相关的东西。 编译器在你的项目源代码中遇到的任何其他标识符(或其类)也是如此。99%这样的问题可以通过做一个 "搜索 "来解决。

© www.soinside.com 2019 - 2024. All rights reserved.