全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1214
推到 Plurk!
推到 Facebook!

傳 array

答題得分者是:danny
QOO10
初階會員


發表:59
回覆:89
積分:29
註冊:2002-12-25

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-12-26 09:12:12 IP:61.229.xxx.xxx 未訂閱
各位好,定義type na 等於二維array,在同unit 傳是沒問題但,跨越第兩個 unit 時??不知如何解!!(incompatable type)!! unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type na=array of array of string; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var aa:na; begin SetLength(aa,2); setlength(aa[0],2); aa[0][1]:='aaa'; form2.test(aa); end; end. ----------------------------------- unit Unit2; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type na=array of array of string; type TForm2 = class(TForm) private { Private declarations } public { Public declarations } procedure test(bb:na); end; var Form2: TForm2; implementation procedure TForm2.test(bb:na); begin showmessage(bb[0][1]); end; {$R *.DFM} end.
danny
版主


發表:100
回覆:522
積分:595
註冊:2002-03-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-12-26 09:24:31 IP:210.202.xxx.xxx 未訂閱
引言: 各位好,定義type na 等於二維array,在同unit 傳是沒問題但,跨越第兩個 unit 時??不知如何解!!(incompatable type)!! unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type na=array of array of string; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var aa:na; begin SetLength(aa,2); setlength(aa[0],2); aa[0][1]:='aaa'; form2.test(aa); end; end. ----------------------------------- unit Unit2; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type na=array of array of string; type TForm2 = class(TForm) private { Private declarations } public { Public declarations } procedure test(bb:na); end; var Form2: TForm2; implementation procedure TForm2.test(bb:na); begin showmessage(bb[0][1]); end; {$R *.DFM} end.
只要將紅色那行放到一個共用的 Units, 要用的 Form 再 uses 就能用了 雖然藍色那行和紅色那行宣告一樣, 但 Delphi 會視為不同的型態
------
將問題盡快結案也是一種禮貌!
QOO10
初階會員


發表:59
回覆:89
積分:29
註冊:2002-12-25

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-12-26 10:18:07 IP:61.229.xxx.xxx 未訂閱
引言:
引言: 各位好,定義type na 等於二維array,在同unit 傳是沒問題但,跨越第兩個 unit 時??不知如何解!!(incompatable type)!! unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type na=array of array of string; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var aa:na; begin SetLength(aa,2); setlength(aa[0],2); aa[0][1]:='aaa'; form2.test(aa); end; end. ----------------------------------- unit Unit2; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs; type na=array of array of string; type TForm2 = class(TForm) private { Private declarations } public { Public declarations } procedure test(bb:na); end; var Form2: TForm2; implementation procedure TForm2.test(bb:na); begin showmessage(bb[0][1]); end; {$R *.DFM} end.
只要將紅色那行放到一個共用的 Units, 要用的 Form 再 uses 就能用了 雖然藍色那行和紅色那行宣告一樣, 但 Delphi 會視為不同的型態
謝謝您!!您時在太利害了!!
andyca
一般會員


發表:0
回覆:6
積分:1
註冊:2002-12-26

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-12-26 17:15:11 IP:202.95.xxx.xxx 未訂閱
另一個方法: array宣告一次就好,然後在Uses中宣告使用就可 interface和implement中的宣告有可視為公用宣告 只要注意不要交互參考
引言: 各位好,定義type na 等於二維array,在同unit 傳是沒問題但,跨越第兩個 unit 時??不知如何解!!(incompatable type)!! unit Unit1; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls; type na=array of array of string; type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation uses Unit2; {$R *.DFM} procedure TForm1.Button1Click(Sender: TObject); var aa:na; begin SetLength(aa,2); setlength(aa[0],2); aa[0][1]:='aaa'; form2.test(aa); end; end. ----------------------------------- unit Unit2; interface uses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, Unit1; //Remove this line //type na=array of array of string; type TForm2 = class(TForm) private { Private declarations } public { Public declarations } procedure test(bb:na); end; var Form2: TForm2; implementation procedure TForm2.test(bb:na); begin showmessage(bb[0][1]); end; {$R *.DFM} end.
系統時間:2024-05-07 16:19:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!