这种是什么用法? |
尚未結案
|
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
|
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
Unit1: unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls,Unit2; type TCBnames=(Cb1,Cb2,Cb3); TForm1 = class(TForm) Button1: TButton; ComboBox1: TComboBox; ComboBox2: TComboBox; ComboBox3: TComboBox; procedure Button1Click(Sender: TObject); private { Private declarations } //TCBnames=('Combobox1','Combobox2','Combobox3'); function getFlowUnit(CBname:TCBnames):string; //function getFlowUnit:string; public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} { TForm1 } (*function TForm1.getFlowUnit; begin result:=combobox1.text; end; *) procedure TForm1.Button1Click(Sender: TObject); var FU:Tepaswmm; begin FU:=Tepaswmm.create; FU.getflowunit:=self.getflowunit(cb3); //fu.getflowunit:=ComboBox1.text; //FU.getflowunit:=self.getflowunit ; Fu.dosomething; end; function TForm1.getFlowUnit(CBname: TCBnames): string; begin case CBname of Cb1: result:=ComboBox1.text; Cb2: result:=ComboBox2.Text; Cb3: result:=ComboBox3.Text; end; end; end. Unit2: unit Unit2; interface uses dialogs; type TgetFlowUnit=function(): string of object; type Tepaswmm=class private FgetFlowUnit:TgetFlowUnit; public property getflowunit:TgetFlowUnit read FgetFlowUnit write FgetFlowUnit; procedure Dosomething; end; implementation { Tepaswmm } procedure Tepaswmm.Dosomething; begin showmessage(FgetFlowUnit); end; end. why cant it be compiled? the compiler said [Error] Unit1.pas(47): Incompatible types: 'TgetFlowUnit' and 'String' what i want to do is transfer ComBoBox1.text,ComBoBox2.text,ComBoBox3.text in Unit2's dosomething's procedure. hope someone can help me ! thanx! |
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
type TGetFlowUnit = function(): string of object;是指宣告了一個型態為 TGetFlowUnit 的 function, 其回傳值型態為 string 而這種 function 須用在 TObject(或後代) 也就是它是一個物件的 method procedure TForm1.Button1Click(Sender: TObject); var FU: Tepaswmm; begin FU := Tepaswmm.create; FU.GetFlowUnit := self.GetFlowUnit(cb3); FU.GetFlowUnit 其宣告是 property GetFlowUnit: TGetFlowUnit 也就是其型態為 TGetFlowUnit 但是 Self.GetFlowUnit 的回傳值型態為 string 兩者型態不同, 所以會有 Incompatible types: 'TgetFlowUnit' and 'String' 的錯誤出現 其實上面 FU.GetFlowUnit := 動作與如下的動作是類似的 Form1.Button1Click := Button1Click; 只是型態不同而己 end;-- QBQ: 我能做什麼? |
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
I HAVE MADE SOME CHANGES:
REDECLARE
type
TCBnames=(Cb1,Cb2,Cb3);
TgetFlowUnit=function(CB:TCBnames): string of object;
end; but compiler said :[Error] combotest2.pas(28): Not enough actual parameters.
showmessage(FgetFlowUnit); //it said not enough actual parameters here; Therefore I change it like: showmessage(FgetFlowUnit(Cb1)); but compiler said: [Error] combotest1.pas(61): Incompatible types: 'TgetFlowUnit' and 'String'
FU.getflowunit:=self.getflowunit(cb1); //Incompatible types: 'TgetFlowUnit' and 'String'. The details code are:
Unit1: unit combotest1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,combotest2, ComCtrls; type
TCBnames=(Cb1,Cb2,Cb3);
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
Button2: TButton;
Edit1: TEdit;
UpDown1: TUpDown; procedure Button1Click(Sender: TObject);
private
function getFlowUnit(CBname:TCBnames):string;
public
{ Public declarations }
end;
var
Form1: TForm1; implementation {$R *.dfm} { TForm1 }
function TForm1.getFlowUnit(CBname: TCBnames): string;
begin
case CBname of
Cb1: result:=ComboBox1.text;
Cb2: result:=ComboBox2.Text;
Cb3: result:=ComboBox3.Text;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
var
FU:Tepaswmm;
begin
FU:=Tepaswmm.create;
FU.getflowunit:=self.getflowunit(cb1);
Fu.dosomething;
end;
end. Unit2:
unit combotest2; interface
uses
dialogs; type
TCBnames=(Cb1,Cb2,Cb3);
TgetFlowUnit=function(CB:TCBnames): string of object;
//TgetFlowUnit=function(): string of object;
type
Tepaswmm=class
private
FgetFlowUnit{,Fgetcombox2,Fgetcombox3}:TgetFlowUnit;
public
property getflowunit:TgetFlowUnit read FgetFlowUnit write FgetFlowUnit;
procedure Dosomething;
end;
implementation { Tepaswmm } procedure Tepaswmm.Dosomething;
begin
showmessage(FgetFlowUnit(Cb1));
end; end. Hope you can slove this problem for me!
thanx
|
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
I HAVE MADE SOME CHANGES:
REDECLARE
type
TCBnames=(Cb1,Cb2,Cb3);
TgetFlowUnit=function(CB:TCBnames): string of object;
end; but compiler said :[Error] combotest2.pas(28): Not enough actual parameters.
showmessage(FgetFlowUnit); //it said not enough actual parameters here; Therefore I change it like: showmessage(FgetFlowUnit(Cb1)); but compiler said: [Error] combotest1.pas(61): Incompatible types: 'TgetFlowUnit' and 'String'
FU.getflowunit:=self.getflowunit(cb1); //Incompatible types: 'TgetFlowUnit' and 'String'. The details code are:
Unit1: unit combotest1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,combotest2, ComCtrls; type
TCBnames=(Cb1,Cb2,Cb3);
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
Button2: TButton;
Edit1: TEdit;
UpDown1: TUpDown; procedure Button1Click(Sender: TObject);
private
function getFlowUnit(CBname:TCBnames):string;
public
{ Public declarations }
end;
var
Form1: TForm1; implementation {$R *.dfm} { TForm1 }
function TForm1.getFlowUnit(CBname: TCBnames): string;
begin
case CBname of
Cb1: result:=ComboBox1.text;
Cb2: result:=ComboBox2.Text;
Cb3: result:=ComboBox3.Text;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
var
FU:Tepaswmm;
begin
FU:=Tepaswmm.create;
FU.getflowunit:=self.getflowunit(cb1);
Fu.dosomething;
end;
end. Unit2:
unit combotest2; interface
uses
dialogs; type
TCBnames=(Cb1,Cb2,Cb3);
TgetFlowUnit=function(CB:TCBnames): string of object;
//TgetFlowUnit=function(): string of object;
type
Tepaswmm=class
private
FgetFlowUnit{,Fgetcombox2,Fgetcombox3}:TgetFlowUnit;
public
property getflowunit:TgetFlowUnit read FgetFlowUnit write FgetFlowUnit;
procedure Dosomething;
end;
implementation { Tepaswmm } procedure Tepaswmm.Dosomething;
begin
showmessage(FgetFlowUnit(Cb1));
end; end. Hope you can slove this problem for me!
thanx
|
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
I HAVE MADE SOME CHANGES:
REDECLARE
type
TCBnames=(Cb1,Cb2,Cb3);
TgetFlowUnit=function(CB:TCBnames): string of object;
end; but compiler said :[Error] combotest2.pas(28): Not enough actual parameters.
showmessage(FgetFlowUnit); //it said not enough actual parameters here; Therefore I change it like: showmessage(FgetFlowUnit(Cb1)); but compiler said: [Error] combotest1.pas(61): Incompatible types: 'TgetFlowUnit' and 'String'
FU.getflowunit:=self.getflowunit(cb1); //Incompatible types: 'TgetFlowUnit' and 'String'. The details code are:
Unit1: unit combotest1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,combotest2, ComCtrls; type
TCBnames=(Cb1,Cb2,Cb3);
TForm1 = class(TForm)
Button1: TButton;
ComboBox1: TComboBox;
ComboBox2: TComboBox;
ComboBox3: TComboBox;
Button2: TButton;
Edit1: TEdit;
UpDown1: TUpDown; procedure Button1Click(Sender: TObject);
private
function getFlowUnit(CBname:TCBnames):string;
public
{ Public declarations }
end;
var
Form1: TForm1; implementation {$R *.dfm} { TForm1 }
function TForm1.getFlowUnit(CBname: TCBnames): string;
begin
case CBname of
Cb1: result:=ComboBox1.text;
Cb2: result:=ComboBox2.Text;
Cb3: result:=ComboBox3.Text;
end;
end; procedure TForm1.Button1Click(Sender: TObject);
var
FU:Tepaswmm;
begin
FU:=Tepaswmm.create;
FU.getflowunit:=self.getflowunit(cb1);
Fu.dosomething;
end;
end. Unit2:
unit combotest2; interface
uses
dialogs; type
TCBnames=(Cb1,Cb2,Cb3);
TgetFlowUnit=function(CB:TCBnames): string of object;
//TgetFlowUnit=function(): string of object;
type
Tepaswmm=class
private
FgetFlowUnit{,Fgetcombox2,Fgetcombox3}:TgetFlowUnit;
public
property getflowunit:TgetFlowUnit read FgetFlowUnit write FgetFlowUnit;
procedure Dosomething;
end;
implementation { Tepaswmm } procedure Tepaswmm.Dosomething;
begin
showmessage(FgetFlowUnit(Cb1));
end; end. Hope you can slove this problem for me!
thanx
|
wuabc
初階會員 發表:6 回覆:60 積分:33 註冊:2002-10-28 發送簡訊給我 |
引言: I HAVE MADE SOME CHANGES: REDECLARE type TCBnames=(Cb1,Cb2,Cb3); TgetFlowUnit=function(CB:TCBnames): string of object; end; but compiler said :[Error] combotest2.pas(28): Not enough actual parameters. showmessage(FgetFlowUnit); //it said not enough actual parameters here; Right here you can say that you want to call a FUNCTION to get a string result, so, when you call the FUNCTION you need to pass a parameter i.e. CB that you defined above Therefore I change it like: showmessage(FgetFlowUnit(Cb1)); but compiler said: [Error] combotest1.pas(61): Incompatible types: 'TgetFlowUnit' and 'String' FU.getflowunit:=self.getflowunit(cb1); //Incompatible types: 'TgetFlowUnit' and 'String'. And here, you just tell FU that 'self.getflowunit' is you are, that means you just assign a method (a pointer) to FU.getflowunit only, so you don't need any parameter with, like as: FU.getflowunit := self.getflowunit; |
lhh
一般會員 發表:16 回覆:21 積分:7 註冊:2004-11-14 發送簡訊給我 |
|
Chance36
版主 發表:31 回覆:1033 積分:792 註冊:2002-12-31 發送簡訊給我 |
引言: [Error] combotest1.pas(68): Incompatible types: 'combotest2.TCBnames' and 'combotest1.TCBnames'同樣是TCBnames 的型態,但一個是Combotest1 Unit 中的TCBNames 另一個卻是ComboTest2 Unit 中的TCBnames ,看起來一樣其實對Delphi來說是不一樣的型態 建議你將Combotest1的 Type TCBnames=(Cb1,Cb2,Cb3); 這行定義拿掉即可, 因為Combotest1 有uses 到Combotest2,所以其中的TCBnames會用到同樣是Combotest2裏面定義的TCBnames。 _______________________________________ <>深藍的魚>,祝您好運..........連連 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |