2012-01-06 16 views
1

爲什麼我得到這個錯誤,我用listview替換了一個stringgrid,然後將其設置爲viewstyle vsreport,但我得到了一個錯誤,如(預期'='但'(' 發現)它閃爍在此過程如下修正Delphi中的窗體中的方法聲明中的錯誤

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; 

回答

4

在事件處理程序的聲明擺脫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; 
+0

對不起,我有一個錯字錯誤..現在的問題是它試圖編譯,但有一個錯誤,說列表索引超出界限 – 2012-01-06 03:50:21

+0

在哪條線上?你需要更具體。 – 2012-01-06 06:07:54

+0

它在高清程序後的重新加載程序,是否可以,如果我郵寄給你的小項目?我怎麼能附加在這裏?代碼是相當巨大的......或者我應該只是在這裏粘貼 – 2012-01-06 10:40:07

-1

爲什麼單位「結束」出現在下面的過程中:

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. 

除非你發佈來自多個單位代碼,將其移動到單位文件的末尾。

+0

的'end.'不是在過程中。 – 2012-01-06 03:09:55