線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:1245
推到 Plurk!
推到 Facebook!

如何得知例舉裡有多少元素?

答題得分者是:ccchen
m0210
一般會員


發表:31
回覆:29
積分:17
註冊:2002-08-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-23 00:56:25 IP:211.22.xxx.xxx 未訂閱
Procedure TFORM1.Button1Click(sender:TObject); Type Ttest=(t1,t2,t3,t4); Begin 依上例宣告,要如何得知宣告裡有多少元素呢? 我使用了Showmessage(inttostr(high(Ttest));這樣行不通, 麻煩各位大大幫忙提供解答...謝謝 end;
flyup
資深會員


發表:280
回覆:508
積分:385
註冊:2002-04-15

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-23 01:06:44 IP:61.225.xxx.xxx 未訂閱
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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-01-23 07:59:08 IP:202.39.xxx.xxx 未訂閱
procedure TForm1.Button1Click(Sender: TObject);
Type
  TTest = (t1, t2, t3, t4);
var
  FT: TTest;
  i: integer;
Begin
  i := 0;
  for FT := Low(TTest) to High(TTest) do
    Inc(i);      ShowMessage(IntToStr(i))
end;
-- 將進酒 杯莫停 與君歌一曲 請君為我傾耳聽
ccchen
版主


發表:61
回覆:940
積分:1394
註冊:2002-04-15

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-01-23 08:23:24 IP:61.219.xxx.xxx 未訂閱
改成這樣就可以了 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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-01-29 23:57:42 IP:211.22.xxx.xxx 未訂閱
謝謝各位~問題以解決
系統時間:2024-05-05 6:05:02
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!