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

StringGrid問題

答題得分者是:jest0024
心情之風
一般會員


發表:14
回覆:9
積分:4
註冊:2005-05-10

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-05-19 06:13:35 IP:218.175.xxx.xxx 未訂閱
可以幫我檢查一下這格程式嗎 因為我不知道問題出在哪裡 所以我不知道從何改起 下面是我COMPILER隻厚當我按下取得LOC之後就變成這樣了
procedure TForm2.Button4Click(Sender: TObject);
Var
  X:Integer;
  temp,loc:string;
  i,j,l,loctemp : Integer;    begin
  X := 0;
  While X < RowCount Do
    Begin
      temp := StringGrid1.Cells[3,X];
      If temp = 'START' then
      begin
        loc := stringgrid1.Cells[4,X];
        If loc.Length<4 then
          begin
            j := loc.Length;
            l := loc.Length;
            for i:=3-j downto 0 do
              begin
                loc := '0'+loc;
                inc(j);
              end;
            end;
        Stringgrid1.Cells[1,X+1] := loc;
        inc(X);
      end
      else if temp = 'RESW' then
      begin
        loc:=stringgrid1.Cells[1,X];
        l := loc.Length;
        loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
        loctemp:=loctemp+(StrToInt(stringgrid1.Cells[4,X])*3);
        loc := IntToHex(loctemp,4);
        Stringgrid1.Cells[1,X+1] := loc;
        inc(X);
      end
      else if temp = 'RESB' then
      begin
        loc:=stringgrid1.Cells[1,X];
        l := loc.Length;
        loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
        loctemp:=loctemp+(StrToInt(stringgrid1.Cells[4,X])*1);
        loc := IntToHex(loctemp,4);
        Stringgrid1.Cells[1,X+1] := loc;
        inc(X);
      end
      else if temp = 'BYTE' then
      begin
        temp := LeftStr(stringgrid1.Cells[4,X+1],1);
        If temp = 'c' then
        begin
          loc:=stringgrid1.Cells[1,X];
        end;
        l := loc.Length;
        loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
        loctemp:=loctemp+(StrToInt(stringgrid1.Cells[4,X])*1);
        loc := IntToHex(loctemp,4);
        Stringgrid1.Cells[1,X+1] := loc;
        inc(X);
      end
      else if temp = 'BYTE' then
      begin
        temp := LeftStr(stringgrid1.Cells[4,X+1],1);
        If temp = 'x' then
        begin
          temp := stringgrid1.Cells[4,X];
        end;
        temp := Copy(temp,3,temp.Length-1);
        loc:=stringgrid1.Cells[1,X+1];
        l := loc.Length;
        loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
        loctemp:=loctemp+(temp.Length-1);
        loc := IntToHex(loctemp,4);
        Stringgrid1.Cells[1,X+1] := loc;
        inc(X);
      end
      else
      begin
        loc:=stringgrid1.Cells[1,X];
        l := loc.Length;
        loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
        loctemp:=loctemp+3;
        loc := IntToHex(loctemp,4);
        Stringgrid1.Cells[1,X+1] := loc;
        inc(X);
      end;
    end;        end;    end.
發表人 - 心情之風 於 2005/05/19 06:14:29
P.D.
版主


發表:603
回覆:4038
積分:3874
註冊:2006-10-31

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-05-19 08:48:12 IP:61.71.xxx.xxx 未訂閱
顯然我的delphi5不認識 loc.length的語法(delphi6以上不知是否支援), 可嘗試改用 length(loc), 這不是重點 另外重點是我們手上沒有資料可以測, 問題應該出現在你post這段程式內的計算公式, 你可以先以Debug方式來追蹤看到底在讀到第幾個row, 在那一段 if 的那一行會down出這個訊息, 再來查這行為何會導致問題! 你可以在 x:= 0 這行設定中斷點(只要用滑鼠click 兩次即可), 然後Project->Run, 按下取得loc鍵後程式就會在x:= 0停下來, 接下來用 F8 來Step by Step的一列列執行就可以找出錯誤點了! 發表人 - P.D. 於 2005/05/19 08:51:27
心情之風
一般會員


發表:14
回覆:9
積分:4
註冊:2005-05-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2005-05-19 08:57:50 IP:218.175.xxx.xxx 未訂閱
在DEBUG CALL STACK視窗裡顯示的是 Process is not accessible 在EVENT LOG 視窗裡顯示的是 Module Load: mscorlib. No Debug Info. Base Address: $79780000. Process Project1.exe (340) Thread Start: Thread ID: 200. Process Project1.exe (340) Process Start: Attached/Spawned Process 0x154. Process Project1.exe (340) Module Load: Project1. No Debug Info. Base Address: $00400000. Process Project1.exe (340) Module Load: borland.delphi. No Debug Info. Base Address: $03000000. Process Project1.exe (340) Module Load: borland.vclrtl. No Debug Info. Base Address: $03020000. Process Project1.exe (340) Module Load: borland.vcl. No Debug Info. Base Address: $03230000. Process Project1.exe (340) Module Load: system. No Debug Info. Base Address: $7B0A0000. Process Project1.exe (340) Module Load: system.drawing. No Debug Info. Base Address: $03630000. Process Project1.exe (340) Thread Start: Thread ID: 4076. Process Project1.exe (340) Process Start: Attached/Spawned Process 0x154. Process Project1.exe (340) Module Unload: Project1. Process Project1.exe (340) Module Unload: borland.delphi. Process Project1.exe (340) Module Unload: borland.vclrtl. Process Project1.exe (340) Module Unload: borland.vcl. Process Project1.exe (340) Module Unload: system. Process Project1.exe (340) Module Unload: system.drawing. Process Project1.exe (340) Module Unload: mscorlib. Process Project1.exe (340) Thread Exit: Thread ID: 200. Process Project1.exe (340) 其他DEBUG視窗裡都沒有東西
jest0024
高階會員


發表:11
回覆:310
積分:224
註冊:2002-11-24

發送簡訊給我
#4 引用回覆 回覆 發表時間:2005-05-19 09:22:52 IP:211.74.xxx.xxx 未訂閱
問題多多實在看不懂,使用Delphi7也無法編譯你這段源碼..:(
1.loc.Length、loc.Chars[1]
  應該不屬pascal吧,倒類似C呢!!
2.loc:=stringgrid1.Cells[1,X];
  若是得到LOC是個空字串
  loc.Chars[1])*16*16*16 StrToInt(loc...怎能使用呢?!
ps.附HexToInt Function    function HexToInt(Const Str:String):Integer;
var
  i,j:Integer;
begin
  Result:=0;
  for i:=1 to Length(Str) do begin
    Case Str[i] of
      '0'..'9':j:=Ord(Str[i])-Ord('0');
      'a'..'f':j:=Ord(Str[i])-Ord('a') $A;
      'A'..'F':j:=Ord(Str[i])-Ord('A') $A;
      else     j:=0;
    end;
    Result:=(Result shl 4)   j;
  end;
end;
發表人 - jest0024 於 2005/05/19 09:23:34
心情之風
一般會員


發表:14
回覆:9
積分:4
註冊:2005-05-10

發送簡訊給我
#5 引用回覆 回覆 發表時間:2005-05-19 09:37:23 IP:218.175.xxx.xxx 未訂閱
我是用DELPHI8在寫的 那些是裡面副加的指令就是假設說打STRINGGRID1"." 之後就會自己跑出來可以用的函式可是如果說我把裡面判別BYTE的地方拿掉 中間的loc:=stringgrid1.Cells[1,X];改成loc:=stringgrid1.Cells[1,X+1]; 還有把16進位那邊用CASE寫成
l := loc.Length;
        case l of
          4:loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
          3:loctemp:=StrToInt(loc.Chars[1])*16*16+StrToInt(loc.Chars[2])*16+StrToInt(loc.Chars[3])*1;
          2:loctemp:=StrToInt(loc.Chars[1])*16+StrToInt(loc.Chars[2])*1;
          1:loctemp:=StrToInt(loc.Chars[1])*1;
        end;
這樣的話就會變成這樣...不過第一個LOC的值抓不到應該要是1003不是0003 發表人 - 心情之風 於 2005/05/19 09:40:04
wameng
版主


發表:31
回覆:1336
積分:1188
註冊:2004-09-16

發送簡訊給我
#6 引用回覆 回覆 發表時間:2005-05-19 10:34:35 IP:61.222.xxx.xxx 未訂閱
我認為出現這個錯誤是當然會的。 主要是作者根本沒有考慮字串是否為空。 當字串為空時,讀取 Loc.Chars[1] 當然會出現錯誤訊息。 loc:=stringgrid1.Cells[1,X]; l := loc.Length; if l>0 then begin loctemp:=StrToInt(loc.Chars[1])*16*16*16 StrToInt(loc.Chars[2])*16*16 StrToInt(loc.Chars[3])*16 StrToInt(loc.Chars[4])*1; loctemp:=loctemp 3; loc := IntToHex(loctemp,4); Stringgrid1.Cells[1,X 1] := loc; end; ~~~~~~~~~~~ 難得聰明,常常糊塗。 ~~~~~~~~~~~
jest0024
高階會員


發表:11
回覆:310
積分:224
註冊:2002-11-24

發送簡訊給我
#7 引用回覆 回覆 發表時間:2005-05-19 14:09:46 IP:61.60.xxx.xxx 未訂閱
引言: 我是用DELPHI8在寫的 那些是裡面副加的指令就是假設說打STRINGGRID1"." 之後就會自己跑出來可以用的函式可是如果說我把裡面判別BYTE的地方拿掉 中間的loc:=stringgrid1.Cells[1,X];改成loc:=stringgrid1.Cells[1,X+1]; 還有把16進位那邊用CASE寫成
l := loc.Length;
        case l of
          4:loctemp:=StrToInt(loc.Chars[1])*16*16*16+StrToInt(loc.Chars[2])*16*16+StrToInt(loc.Chars[3])*16+StrToInt(loc.Chars[4])*1;
          3:loctemp:=StrToInt(loc.Chars[1])*16*16+StrToInt(loc.Chars[2])*16+StrToInt(loc.Chars[3])*1;
          2:loctemp:=StrToInt(loc.Chars[1])*16+StrToInt(loc.Chars[2])*1;
          1:loctemp:=StrToInt(loc.Chars[1])*1;
        end;
這樣的話就會變成這樣...不過第一個LOC的值抓不到應該要是1003不是0003 發表人 - 心情之風 於 2005/05/19 09:40:04
判斷一下loc是否為空字串?loctemp是否為1000? 個人認為loc應為空字串,故之前會造成錯誤,而現在改成case l of...則造成 值為0! 發表人 - jest0024 於 2005/05/19 14:12:31
系統時間:2024-06-29 17:08:14
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!