如何存取另一個Form的AdoDataSet資料?? |
尚未結案
|
jeffreck
高階會員 ![]() ![]() ![]() ![]() 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
請教各位前輩
如何存取另一個Form的AdoDataSet資料?? 在程式中有兩個From為 AFORM ,BForm
在AFORM中有TADODataSet物件名為dstDetail 在AForm中執行ShowMessage(dstDetail.FieldByName('PurchaseID').Value);
正常,
但在BForm中執行ShowMessage(AForm.dstDetail.FieldByName('PurchaseID').Value);
就會錯誤,不知為何?? 非常非常的謝謝你,因為有你這世界變的更美好 ☆ ^_^ ☆
°∴°﹒☆°.﹒‧°∴°﹒°.﹒‧°∴°﹒
﹒‧°∴°﹒☆°.﹒‧°∴°﹒°.﹒‧°∴°﹒﹒‧°∴°﹒☆°.
|
channel
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:67 回覆:707 積分:854 註冊:2002-05-02 發送簡訊給我 |
引言: 請教各位前輩 如何存取另一個Form的AdoDataSet資料?? 在程式中有兩個From為 AFORM ,BForm 在AFORM中有TADODataSet物件名為dstDetail 在AForm中執行ShowMessage(dstDetail.FieldByName('PurchaseID').Value); 正常, 但在BForm中執行ShowMessage(AForm.dstDetail.FieldByName('PurchaseID').Value); 就會錯誤,不知為何?? 非常非常的謝謝你,因為有你這世界變的更美好 ☆ ^_^ ☆ °∴°﹒☆°.﹒‧°∴°﹒°.﹒‧°∴°﹒ ﹒‧°∴°﹒☆°.﹒‧°∴°﹒°.﹒‧°∴°﹒﹒‧°∴°﹒☆°.
------
~小弟淺見,參考看看~ |
jeffreck
高階會員 ![]() ![]() ![]() ![]() 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
引言:謝謝channel前輩回覆 謝謝channel前輩的回答 我是用 Available forms 的方式 Create Form 是用之前輩貼出的方法 因該是這問題,但不知要如何修正 OpenForm('TAForm') function OpenForm(FormClass:TFormClass):TFormclass; var i : integer; Fm : TForm; begin fm := nil; for i := 0 to Screen.FormCount - 1 do if Screen.Forms[i] is FormClass then begin Fm := Screen.Forms[i]; if Fm.WindowState = wsMinimized then Fm.WindowState := wsNormal; Fm.BringToFront; end; if not assigned(fm) then fm := FormClass.Create(Application); fm.Show; result := TFormClass(Fm); end; function OpenForm(fmName: string):TFormclass; begin Result := TFormClass(FindClass(fmName)); try try OpenForm(Result); except on E:Exception do ShowMessage(E.Message); end; except ShowMessage(fmname ' 尚未建立'); end; end; 謝謝........ |
channel
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:67 回覆:707 積分:854 註冊:2002-05-02 發送簡訊給我 |
引言: 謝謝channel前輩回覆 謝謝channel前輩的回答 我是用 Available forms 的方式 Create Form 是用之前輩貼出的方法 因該是這問題,但不知要如何修正 OpenForm('TAForm') function OpenForm(FormClass:TFormClass):TFormclass; var i : integer; Fm : TForm; begin fm := nil; for i := 0 to Screen.FormCount - 1 do if Screen.Forms[i] is FormClass then begin Fm := Screen.Forms[i]; if Fm.WindowState = wsMinimized then Fm.WindowState := wsNormal; Fm.BringToFront; end; if not assigned(fm) then fm := FormClass.Create(Application); fm.Show; result := TFormClass(Fm); end; function OpenForm(fmName: string):TFormclass; begin Result := TFormClass(FindClass(fmName)); try try OpenForm(Result); except on E:Exception do ShowMessage(E.Message); end; except ShowMessage(fmname ' 尚未建立'); end; end; 謝謝........可否貼出您在BForm的程式碼?
------
~小弟淺見,參考看看~ |
jeffreck
高階會員 ![]() ![]() ![]() ![]() 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
引言: 可否貼出您在BForm的程式碼?謝謝channel前輩回覆 以下為BForm程式 APF010為AForm APF011為BForm ----------------------------------------------------------------------- unit APF011_; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, ActnList, ExtCtrls; type TAPF011 = class(TForm) dstMaster: TADODataSet; dtsMaster: TDataSource; DBGrid1: TDBGrid; ActionList1: TActionList; atEnter: TAction; dstMasterPurchaseType: TSmallintField; dstMasterSubTotal: TBCDField; dstMasterValueAddTax: TBCDField; dstMasterAmount: TBCDField; dstMasterAccountPayable: TBCDField; dstMasterPaid: TBCDField; dstMasterPurchaseTypeName: TStringField; dstMasterPurchaseDate: TDateTimeField; dstMasterPurchaseID: TWideStringField; dstMasternotPaid: TBCDField; dstMasterNowAccountPayable: TBCDField; dstMasterNowPaid: TBCDField; procedure FormCreate(Sender: TObject); procedure DBGrid1DblClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var APF011: TAPF011; implementation uses APF010_,SYMain_; {$R *.dfm} procedure TAPF011.FormCreate(Sender: TObject); begin self.dstMaster.Open; end; procedure TAPF011.DBGrid1DblClick(Sender: TObject); begin ShowMessage(APF010.dstDetail.FieldByName('PurchaseID').Value); APF010.dstDetailPurchaseType.value :=self.dstMaster.fieldByName('PurchaseType').value ; APF010.dstDetail.FieldByName('PurchaseID').Value :=self.dstMaster.fieldByName('PurchaseID').value ; self.Close; end; end. |
wuabc
初階會員 ![]() ![]() 發表:6 回覆:60 積分:33 註冊:2002-10-28 發送簡訊給我 |
|
channel
尊榮會員 ![]() ![]() ![]() ![]() ![]() ![]() 發表:67 回覆:707 積分:854 註冊:2002-05-02 發送簡訊給我 |
引言:jeffreck: 您說APF010是Available forms也就是代表必須下程式動態開啟,而不是程式一執行就會開啟此Form,雖然您在APF011有uses APF010_;但在未CreateAPF010就存取APF010之TADODataSet,便會造成錯誤,我在第一次回覆時已有說明要先Create APF010,所以補上紅色的部份即可,您可以試試看…引言: 可否貼出您在BForm的程式碼?謝謝channel前輩回覆 以下為BForm程式 APF010為AForm APF011為BForm ----------------------------------------------------------------------- unit APF011_; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, DB, ADODB, StdCtrls, Grids, DBGrids, ActnList, ExtCtrls; type TAPF011 = class(TForm) dstMaster: TADODataSet; dtsMaster: TDataSource; DBGrid1: TDBGrid; ActionList1: TActionList; atEnter: TAction; dstMasterPurchaseType: TSmallintField; dstMasterSubTotal: TBCDField; dstMasterValueAddTax: TBCDField; dstMasterAmount: TBCDField; dstMasterAccountPayable: TBCDField; dstMasterPaid: TBCDField; dstMasterPurchaseTypeName: TStringField; dstMasterPurchaseDate: TDateTimeField; dstMasterPurchaseID: TWideStringField; dstMasternotPaid: TBCDField; dstMasterNowAccountPayable: TBCDField; dstMasterNowPaid: TBCDField; procedure FormCreate(Sender: TObject); procedure DBGrid1DblClick(Sender: TObject); private { Private declarations } public { Public declarations } end; var APF011: TAPF011; implementation uses APF010_,SYMain_; {$R *.dfm} procedure TAPF011.FormCreate(Sender: TObject); begin self.dstMaster.Open; end; procedure TAPF011.DBGrid1DblClick(Sender: TObject); begin ShowMessage(APF010.dstDetail.FieldByName('PurchaseID').Value); APF010.dstDetailPurchaseType.value :=self.dstMaster.fieldByName('PurchaseType').value ; APF010.dstDetail.FieldByName('PurchaseID').Value :=self.dstMaster.fieldByName('PurchaseID').value ; self.Close; end; end. procedure TAPF011.DBGrid1DblClick(Sender: TObject); begin Application.CreateForm(TAPF010, APF010); ShowMessage(APF010.dstDetail.FieldByName('PurchaseID').Value); APF010.dstDetailPurchaseType.value :=self.dstMaster.fieldByName('PurchaseType').value ; APF010.dstDetail.FieldByName('PurchaseID').Value :=self.dstMaster.fieldByName('PurchaseID').value ; self.Close; end;~小弟淺見,參考看看~ 發表人 - channel 於 2003/09/18 23:14:15
------
~小弟淺見,參考看看~ |
jeffreck
高階會員 ![]() ![]() ![]() ![]() 發表:247 回覆:340 積分:197 註冊:2003-01-23 發送簡訊給我 |
引言: [jeffreck: 您說APF010是Available forms也就是代表必須下程式動態開啟,而不是程式一執行就會開啟此Form,雖然您在APF011有uses APF010_;但在未CreateAPF010就存取APF010之TADODataSet,便會造成錯誤,我在第一次回覆時已有說明要先Create APF010,所以補上紅色的部份即可,您可以試試看…對不起前輩我沒有說清楚: 在BForm(APF011)開啟前AForm(APF010)就己開啟 是用OpenForm('TAForm')這方法如下, 並不是 Application.CreateForm(TAPF010, APF010); 所以才有問題 因要做到用能依字串指定要開啟的Form所以才用OpenForm('TAForm') OpenForm 內容如下:不知能否修正?? function OpenForm(FormClass:TFormClass):TFormclass; var i : integer; Fm : TForm; begin fm := nil; for i := 0 to Screen.FormCount - 1 do if Screen.Forms[i] is FormClass then begin Fm := Screen.Forms[i]; if Fm.WindowState = wsMinimized then Fm.WindowState := wsNormal; Fm.BringToFront; end; if not assigned(fm) then fm := FormClass.Create(Application); fm.Show; result := TFormClass(Fm); end; function OpenForm(fmName: string):TFormclass; begin Result := TFormClass(FindClass(fmName)); try try OpenForm(Result); except on E:Exception do ShowMessage(E.Message); end; except ShowMessage(fmname ' 尚未建立'); end; end;procedure TAPF011.DBGrid1DblClick(Sender: TObject); begin Application.CreateForm(TAPF010, APF010); ShowMessage(APF010.dstDetail.FieldByName('PurchaseID').Value); APF010.dstDetailPurchaseType.value :=self.dstMaster.fieldByName('PurchaseType').value ; APF010.dstDetail.FieldByName('PurchaseID').Value :=self.dstMaster.fieldByName('PurchaseID').value ; self.Close; end;~小弟淺見,參考看看~ 發表人 - channel 於 2003/09/18 23:14:15 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |