全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1316
推到 Plurk!
推到 Facebook!

何為 cardinal absolute Result ?

尚未結案
BGman
初階會員


發表:28
回覆:85
積分:42
註冊:2003-01-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-01-28 09:53:33 IP:211.22.xxx.xxx 未訂閱
下面是一支德國人寫的函式, 我看不懂LCrdTemp: cardinal absolute Result;這句, 另外我覺得LCrdTemp := LCrdTemp * Radix cardinal(Pos(Value[1], HEX_UPPER) - 1);這句也是怪怪的 // translate a radix coded string into an integer function RadixToInt(Value: string; Radix: byte): integer; var LCrdTemp: cardinal absolute Result; begin LCrdTemp := 0; Value := UpperCase(Value); while Value <> '' do begin if not (Pos(Value[1], HEX_UPPER) in [1..Radix]) then raise EMPHException.CreateFmt(ERR_INVALID_RADIXCHAR, [Value[1], Radix]); LCrdTemp := LCrdTemp * Radix cardinal(Pos(Value[1], HEX_UPPER) - 1); Delete(Value, 1,1); end; end; (* try to find the correct radix (based on prefix/suffix) and return the number, known prefixes/suffixes are:
0x, 0X, $, h, H: radix 16
o, O, 0, o, O: radix 8
%, %: radix 2
otherwise: radix 10 *) end.
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-01-28 10:04:32 IP:147.8.xxx.xxx 未訂閱
Extracted from Delphi help:    
引言:Absolute addresses You can create a new variable that resides at the same address as another variable. To do so, put the directive absolute after the type name in the declaration of the new variable, followed by the name of an existing (previously declared) variable. For example, var Str: string[32]; StrLen: Byte absolute Str; specifies that the variable StrLen should start at the same address as Str. Since the first byte of a short string contains the string's length, the value of StrLen is the length of Str. You cannot initialize a variable in an absolute declaration or combine absolute with any other directives.
So replacing LCrdTemp with Result will make it clear?
BGman
初階會員


發表:28
回覆:85
積分:42
註冊:2003-01-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-02-06 10:05:02 IP:211.22.xxx.xxx 未訂閱
var Str: string[32]; StrLen: Byte absolute Str; Happy New Year! Tanks a lot ! I thought that I understood roughly, But I can't realize why "StrLen" this variable used the same address with "Str" ? Is any useful reason for the sample ? "Str" variable has 32 bytes capacity to store data , but StrLen replace the first address. In Delphi the first address of string is record string's length automatically , I am afraid of cause memory error by change the first address of Delphi string. Can you provide another useful sample to me? Help me to realize clearly ! Thank you very much!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-02-06 11:37:56 IP:147.8.xxx.xxx 未訂閱
Happy New Year! From Delphi help:    A ShortString is 0 to 255 characters long. While the length of a ShortString can change dynamically, its memory is a statically allocated 256 bytes; the first byte stores the length of the string, and the remaining 255 bytes are available for characters. If S is a ShortString variable, Ord(S[0]), like Length(S), returns the length of S; assigning a value to S[0], like calling SetLength, changes the length of S. ShortString is maintained for backward compatibility only. So I think changing the first byte (i.e. StrLen) should be fine. BTW Str will take 32 1=33 bytes while StrLen should be a name of a Delphi function? function StrLen(const Str: PChar): Cardinal;
系統時間:2024-05-04 20:38:30
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!