UnTyped Parameter 的判斷 |
答題得分者是:william
|
Nelson Lo
一般會員 發表:35 回覆:87 積分:24 註冊:2003-04-04 發送簡訊給我 |
請教各位
我在函數UnTyped_Test中宣告一個UnTyped 的參數
如果我想要先判斷傳過來的參數是哪種Type (integer or string 等等)
我用 if (intPar is String) then ......
可是編譯會error
能否指點一下
謝謝 procedure TForm1.Button1Click(Sender: TObject);
var
MyParameter : String;
begin
MyParameter := '123';
UnTyped_Test(MyParameter);
end; procedure TForm1.UnTyped_Test(var MyPar);
begin
if (intPar is String) then
ShowMessage(String(intPar));
end;
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
Quoted from Delphi help: Within a procedure or function body, untyped parameters are incompatible with every type. To operate on an untyped parameter, you must cast it. In general, the compiler cannot verify that operations on untyped parameters are valid. So the compiler never know the type of an untyped parameter. BTW, is is used for object/class/interface. If you don't mind the performance, you could use variant, e.g.
procedure TForm1.Button1Click(Sender: TObject); var MyParameter: Variant; begin MyParameter := '123'; UnTyped_Test(MyParameter); MyParameter := 1.23; UnTyped_Test(MyParameter); end; procedure TForm1.UnTyped_Test(var MyPar: Variant); begin if VarIsStr(MyPar) then ShowMessage('string') else if VarIsFloat(MyPar) then ShowMessage('float'); end; |
Nelson Lo
一般會員 發表:35 回覆:87 積分:24 註冊:2003-04-04 發送簡訊給我 |
|
Nelson Lo
一般會員 發表:35 回覆:87 積分:24 註冊:2003-04-04 發送簡訊給我 |
|
Nelson Lo
一般會員 發表:35 回覆:87 積分:24 註冊:2003-04-04 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
引言:再請教一下 在VB中有一種 DataType 可宣告成 as any 例如 Declare Function viGetAttribute Lib "VISA32.DLL" Alias "#133" (ByVal vi As Long, ByVal attrName As Long, attrValue As Any) As Long 那我如果要用delphi呼叫此function的話 參數attrValue 我要宣告成何種type variant 可以嗎I guess Variant or OleVariant will do it. But I don't have VB (and hence less experience with VB), if it is not varaint, then I guess it is some kind of pointer/untype parameter and you will need the information in vi and attrName to type cast it. If you cannot find VarIsFloat, etc. you can use VarType function and check. P.S. I am using Delphi 7 and VasIsxxx are in the Variants unit. |
Nelson Lo
一般會員 發表:35 回覆:87 積分:24 註冊:2003-04-04 發送簡訊給我 |
謝謝您
其實是有一個大概是C寫的DLL的API C Syntax
ViStatus viGetAttribute(ViObject vi, ViAttr attribute,void * ttrState) Visual Basic Syntax
viGetAttribute&(ByVal vi&, ByVal attribute&, attrState as Any) 現在我要用Delphi去Call
我想 as any 應該就是delphi的 variant
不過還是得實際試試
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
Nelson Lo
一般會員 發表:35 回覆:87 積分:24 註冊:2003-04-04 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |