請教程式的錯誤訊息?? |
答題得分者是:BOSS
|
lkkplayer
一般會員 發表:26 回覆:59 積分:17 註冊:2006-11-22 發送簡訊給我 |
請教各位大大,小弟寫了一個小程式
RUN的時候,卻出現下面的錯誤訊息的視窗 Project Sample.exe raised exception class EDatabaseError with message 'Table1: No index currently active'. Process stopped. Use Step or Run to continue. 這個小程式是讀取test.dbf到ListBox1,然後我點其中一項後,就會呼叫SndForm上面會列出我選的項目的相關資料 另外我寫的這個程序不知道對不對procedure SetClickedData(aSource: TDataSource; aTbl:TTable ; const aName : String); 請各位大大我哪裡出了問題了呢? 以下是我的程式碼 第一個Form unit MainForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DB, DBTables, Grids, DBGrids; type TForm1 = class(TForm) DataSource1: TDataSource; Table1: TTable; ListBox1: TListBox; Button1: TButton; Button2: TButton; procedure FormActivate(Sender: TObject); procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure ListBox1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses SndForm; {$R *.dfm} procedure TForm1.FormActivate(Sender: TObject); begin Table1.DatabaseName := GetCurrentDir; Table1.TableName := 'TEST.DBF'; Table1.Active := True; end; procedure TForm1.Button1Click(Sender: TObject); begin Table1.First; While not Table1.EOF do begin ListBox1.Items.Add(Table1.FieldByName('Name').Text); Table1.Next; end; end; procedure TForm1.Button2Click(Sender: TObject); begin ListBox1.Clear; end; procedure TForm1.ListBox1Click(Sender: TObject); var aStr : String; begin aStr := ListBox1.Items[ListBox1.ItemIndex]; Form2.SetClickedData(DataSource1,Table1,aStr); Form2.ShowModal; end; end. 第二個Form unit SndForm; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, DBCtrls, DB, DBTables; type TForm2 = class(TForm) Label1: TLabel; Label2: TLabel; DBText1: TDBText; DBText2: TDBText; aTable: TTable; aDataSource: TDataSource; procedure FormActivate(Sender: TObject); private { Private declarations } aNameStr: String; public { Public declarations } procedure SetClickedData(aSource: TDataSource; aTbl:TTable ; const aName : String); end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.SetClickedData(aSource: TDataSource; aTbl:TTable ; const aName : String); begin aDataSource := aSource; aTable := aTbl; aNameStr := aName; end; procedure TForm2.FormActivate(Sender: TObject); begin DBText1.DataSource := aDataSource; DBText2.DataSource := aDataSource; if aTable.FindKey([aNameStr]) then begin DBText1.DataField := 'NAME'; DBText2.DataField := 'GOOD'; end; end; end. |
BOSS
中階會員 發表:70 回覆:79 積分:64 註冊:2006-11-01 發送簡訊給我 |
|
lkkplayer
一般會員 發表:26 回覆:59 積分:17 註冊:2006-11-22 發送簡訊給我 |
|
BOSS
中階會員 發表:70 回覆:79 積分:64 註冊:2006-11-01 發送簡訊給我 |
|
lkkplayer
一般會員 發表:26 回覆:59 積分:17 註冊:2006-11-22 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |