修复 Delphi 表单中方法声明中的错误

发布于 2024-12-25 08:10:45 字数 2212 浏览 2 评论 0原文

为什么我会收到此错误,我用 listview 替换了 stringgrid,然后将其设置为 viewstyle vsreport 但我收到类似的错误 (expected '=' but '('found) 它在此过程中闪烁,

procedure TForm2.ListView2DblClick(Sender: TObject);

这是我的代码

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls, ComCtrls;

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    ListView1: TListView;
    ListView2: TListView;
    procedure FormCreate(Sender: TObject);
    procedure TForm2.ListView2DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
var
  i: integer;
begin
  // NOTE: this can all be done at design-time so
  // you don't need to do it in code at runtime!
  ListView1.Columns[0].Width := 20;
  ListView2.Columns[0].Width := 20;
  for i := 0 to 49 do begin 
    ListView1.Items.Add.Caption := IntToStr(i);
    with ListView2.Items.Add do begin
      Caption := IntToStr(i);
      SubItems.Add('0'); 
    end;
  end; 
  ListView2.Columns[1].Caption := 'name';
  ListView1.Columns[1].Caption := 'extension'; 
  ListView1.Columns[2].Caption := 'format';
  ListView1.Columns[3].Caption := 'size'; 
  ListView1.Columns[4].Caption := 'date';
  ListView1.Columns[5].Caption := 'addres'; 
end;

procedure TForm2.ListView2DblClick(Sender: TObject);
var
  Item: TListItem;
begin 
  Item := ListView2.Selected;
  if Item = nil then Exit;  
  if (Item.SubItems[0] <> '1024') and (Item.SubItems[0] <> '0') then
    ListView1.Selected := ListView1.Items[StrToInt(Item.SubItems[0])];
end;

end.

procedure HD;
var
  i: integer;
begin
  for i := 0 to 49 do begin
    with form2.ListView1.Items[i] do begin
      SubItems[0] := TABLE[i].name;
      SubItems[1] := TABLE[i].format;
      if TABLE[i].tip then
        SubItems[2] := 'folder'
      else
        SubItems[2] := 'file';
      SubItems[3] := IntToStr(TABLE[i].nach);
      SubItems[4] := IntToStr(TABLE[i].razmer);
    end;
    form2.ListView2.Items[i].SubItems[0] := IntToStr(fat[i]);
  end;
end;

Why am I getting this error, I replaced a stringgrid with a listview, I then set it to viewstyle vsreport but I am getting an error like (expected '=' but '(' found) its flashing on this procedure below

procedure TForm2.ListView2DblClick(Sender: TObject);

this is my code

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, StdCtrls, ComCtrls;

type
  TForm2 = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    ListView1: TListView;
    ListView2: TListView;
    procedure FormCreate(Sender: TObject);
    procedure TForm2.ListView2DblClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

{$R *.dfm}

procedure TForm2.FormCreate(Sender: TObject);
var
  i: integer;
begin
  // NOTE: this can all be done at design-time so
  // you don't need to do it in code at runtime!
  ListView1.Columns[0].Width := 20;
  ListView2.Columns[0].Width := 20;
  for i := 0 to 49 do begin 
    ListView1.Items.Add.Caption := IntToStr(i);
    with ListView2.Items.Add do begin
      Caption := IntToStr(i);
      SubItems.Add('0'); 
    end;
  end; 
  ListView2.Columns[1].Caption := 'name';
  ListView1.Columns[1].Caption := 'extension'; 
  ListView1.Columns[2].Caption := 'format';
  ListView1.Columns[3].Caption := 'size'; 
  ListView1.Columns[4].Caption := 'date';
  ListView1.Columns[5].Caption := 'addres'; 
end;

procedure TForm2.ListView2DblClick(Sender: TObject);
var
  Item: TListItem;
begin 
  Item := ListView2.Selected;
  if Item = nil then Exit;  
  if (Item.SubItems[0] <> '1024') and (Item.SubItems[0] <> '0') then
    ListView1.Selected := ListView1.Items[StrToInt(Item.SubItems[0])];
end;

end.

.

procedure HD;
var
  i: integer;
begin
  for i := 0 to 49 do begin
    with form2.ListView1.Items[i] do begin
      SubItems[0] := TABLE[i].name;
      SubItems[1] := TABLE[i].format;
      if TABLE[i].tip then
        SubItems[2] := 'folder'
      else
        SubItems[2] := 'file';
      SubItems[3] := IntToStr(TABLE[i].nach);
      SubItems[4] := IntToStr(TABLE[i].razmer);
    end;
    form2.ListView2.Items[i].SubItems[0] := IntToStr(fat[i]);
  end;
end;

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

红墙和绿瓦 2025-01-01 08:10:45

删除事件处理程序声明中的 Form2. 部分:

type 
  TForm2 = class(TForm) 
    Edit1: TEdit; 
    Edit2: TEdit; 
    ListView1: TListView; 
    ListView2: TListView; 
    procedure FormCreate(Sender: TObject); 
    procedure ListView2DblClick(Sender: TObject); // <-- here
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 

Get rid of the Form2. portion in the declaration of the event handler:

type 
  TForm2 = class(TForm) 
    Edit1: TEdit; 
    Edit2: TEdit; 
    ListView1: TListView; 
    ListView2: TListView; 
    procedure FormCreate(Sender: TObject); 
    procedure ListView2DblClick(Sender: TObject); // <-- here
  private 
    { Private declarations } 
  public 
    { Public declarations } 
  end; 
余罪 2025-01-01 08:10:45

为什么单元会“结束”?出现在以下过程中:

procedure TForm2.ListView2DblClick(Sender: TObject);
var
  Item: TListItem;
begin 
  Item := ListView2.Selected;
  if Item = nil then Exit;  
  if (Item.SubItems[0] <> '1024') and (Item.SubItems[0] <> '0') then
    ListView1.Selected := ListView1.Items[StrToInt(Item.SubItems[0])];
end;
end.

除非您从多个单元发布代码,否则请将其移动到单元文件的末尾。

Why does the unit "end." appear within the following procedure:

procedure TForm2.ListView2DblClick(Sender: TObject);
var
  Item: TListItem;
begin 
  Item := ListView2.Selected;
  if Item = nil then Exit;  
  if (Item.SubItems[0] <> '1024') and (Item.SubItems[0] <> '0') then
    ListView1.Selected := ListView1.Items[StrToInt(Item.SubItems[0])];
end;
end.

Unless you're posting code from multiple units, move it to the end of the unit file.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文