傳 array |
答題得分者是:danny
|
QOO10
初階會員 發表:59 回覆:89 積分:29 註冊:2002-12-25 發送簡訊給我 |
各位好,定義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 發送簡訊給我 |
引言: 各位好,定義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 發送簡訊給我 |
引言:謝謝您!!您時在太利害了!!引言: 各位好,定義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 發送簡訊給我 |
另一個方法: 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. |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |