如何得知例舉裡有多少元素? |
答題得分者是:ccchen
|
m0210
一般會員 發表:31 回覆:29 積分:17 註冊:2002-08-23 發送簡訊給我 |
|
flyup
資深會員 發表:280 回覆:508 積分:385 註冊:2002-04-15 發送簡訊給我 |
A type declaration specifies an identifier that denotes a type. The syntax for a type declaration is type newTypeName = type where newTypeName is a valid identifier. For example, given the type declaration type TMyString = string; you can make the variable declaration var S: TMyString; A type identifier scope doesn't include the type declaration itself (except for pointer types). So you cannot, for example, define a record type that uses itself recursively.
When you declare a type that is identical to an existing type, the compiler treats the new type identifier as an alias for the old one. Thus, given the declarations type TValue = Real; var
X: Real;
Y: TValue; X and Y are of the same type; at runtime, there is no way to distinguish TValue from Real. This is usually of little consequence, but if your purpose in defining a new type is to utilize runtime type information for example, to associate a Delphi property editor with properties of a particular type the distinction between "different name" and "different type"becomes important. In this case, use the syntax type newTypeName = type type For example, type TValue = type Real; forces the compiler to create a new, distinct type called TValue.
----------------
局局棋盤步步新,
變化無常平常待。
人生相處平常心,
無憂無慮心事成。
----------------
發表人 - flyup 於 2003/01/23 01:11:04
|
hagar
版主 發表:143 回覆:4056 積分:4445 註冊:2002-04-14 發送簡訊給我 |
|
ccchen
版主 發表:61 回覆:940 積分:1394 註冊:2002-04-15 發送簡訊給我 |
改成這樣就可以了
showmessage(inttostr(GetTypeData(Typeinfo(Ttest))^.MaxValue));
[note]傳回最大值, 故是3 GetTypeData可取得 PTypeData,定義在Typinfo.pas中, 對資料型態有詳細資料,如enum型態之minvalue,maxvalue等可參考看看 另使用enum 型態另有幾個function很有用順便提醒你參考
以你的case為例:
GetEnumName(typeinifo(TTest), ord(t2)); //結果為t2之字串
GetEnumValue
Succ
...
|
m0210
一般會員 發表:31 回覆:29 積分:17 註冊:2002-08-23 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |