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

为什么edit.text里有两个字符是运行不了

尚未結案
小丫123
初階會員


發表:85
回覆:62
積分:29
註冊:2004-08-31

發送簡訊給我
#1 引用回覆 回覆 發表時間:2004-11-07 16:50:45 IP:218.64.xxx.xxx 未訂閱
Type
  D1Array=array of double;
  D2Array=array of array of double;
imgwidth,imgheight,imagewidth,imageheight:integer;
procedure TForm1.Button1Click(Sender: TObject);
var
  i,j,k:integer;
  w,h,num:integer;
  s,Data:D2Array;
  max:double;
  rect:Trect;
  E:WideString;
  t:string;
begin
  memo1.Clear ;
  setlength(s,imagewidth,imageHeight);
  setLength(data,10,imagewidth*imageHeight);
  E:= charedit.Text;
  num:=length(E );
 for k:=0 to num-1 do
  begin
   Img.Canvas.Font.Color := clBlack;
   Img.Canvas.Font.Size := 42;
   if E <> '' then
     begin
      img.Canvas.TextOut(0, 0, E[k 1]) ;
      Aimg.picture.Bitmap.Assign(img.picture.Bitmap);
     end;
   if img <> nil then
     begin
      img.Width:= imgwidth;
      img.height:=imgheight;
      w:=img.Width  mod imagewidth;
      img.Width:=img.Width  imagewidth-w;
      w:=img.Width  div imagewidth;
      h:=img.Height mod imageHeight;
      img.Height :=img.Height  imageHeight -h;
      h:= img.Height  div imageHeight;
      max:=0;
      for i:=1 to imagewidth-1 do
        for j:=1 to imageHeight-1  do
          begin
          rect.Left :=w*(i-1);
          rect.Top  :=h*(j-1);
          rect.Right  :=rect.Left  w-1;
          rect.Bottom :=rect.Top  h-1;
          s[i,j]:=statistic(rect,img);
          if s[i,j]>max then
          max:=s[i,j];
          end;
     for j:=0 to imageHeight-1 do
       begin
         for i:=0 to imageWidth-1 do
          begin
          if s[i,j]/max >0.2 then
             Data[k,j*imagewidth i-k*imagewidth]:=0.9
          else
              Data[k,j*imagewidth i-k*imagewidth]:=0.1;
         end;
     end;
  end;
      t:='';
 for j:=0 to 19 do
     begin
       t:=' ';
       for i:=0 to 15 do
      begin
        if  Data[k,j*16 i]>=0.8 then
         t:= t '#' ' ' ;
     if  (Data[k,j*16 i]<=0.2) then
         t:= t '0' ' ' ;
      end;
      memo1.Lines.Add(t);
   end;      end;
end;    procedure TForm1.FormCreate(Sender: TObject);
begin
   imgwidth:=42;
    imgheight:=60;
    imagewidth:=16;
    imageheight:=20;
end;
function TForm1.Statistic(const rect: Trect; img: Timage): integer;
var
  x,y:integer;
begin
  Result:=0;
  for x:=rect.Left  to rect.Right do
   for y:=rect.Top  to rect.Bottom  do
    if img.Canvas.Pixels[x,y]<>16777215 then
      inc(result);
end;
 
在我这个程序中,当charedit.tex是一个字符是运行结果是对的,当输入两个字符时就报错。 恳请前辈们指点
geniustom
版主


發表:100
回覆:303
積分:260
註冊:2003-01-03

發送簡訊給我
#2 引用回覆 回覆 發表時間:2004-11-08 02:10:10 IP:219.68.xxx.xxx 未訂閱
小丫123您好... 麻煩您可否說明一下您程式是如何動作的.. 有何用途..需要什麼功能..或是上一下註解.. 因為您的變數還挺多..沒上住解讀起來很累.. 我有試著幫您TRACE過程式.. 不過實在不懂您要的功能是什麼??? 麻煩您修改一下文章..說明清楚一點< > 方便自己也方便別人唷< > =程式是一種藝術 也是訓練自己的分析規劃= =是段落分明 或是雜亂無章= =是一言以敝 或是廢話連篇= =是一目了然 或是艱深難懂= 體會這份藝術 您會了解另一份喜悅與成就
wameng
版主


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

發送簡訊給我
#3 引用回覆 回覆 發表時間:2004-11-08 12:05:50 IP:61.222.xxx.xxx 未訂閱
我會被 小Y123 給整死....呵呵...    在
原來的:
     for j:=0 to imageHeight-1 do
       begin
         for i:=0 to imageWidth-1 do
          begin
          if s[i,j]/max >0.2 then
             Data[k,j*imagewidth i-k*imagewidth]:=0.9
          else
             Data[k,j*imagewidth i-k*imagewidth]:=0.1;
         end;    真搞不懂為何要減,當K=1,I=0 該整體值會變成 -16。
當然出錯!    因此改為...,就可正常運作。
  E:= charedit.Text;
  num:=length(E );
  memo1.Clear ;
  setlength(s,imagewidth,imageHeight);
 setLength(data,num,imagewidth*imageHeight);
  .......
  .......        for j:=0 to imageHeight-1 do
      for i:=0 to imageWidth-1 do
      begin
        if s[i,j]/max >0.2 then
           Data[k,j*imagewidth i]:=0.9
        else
          Data[k,j*imagewidth i]:=0.1;
     end;
小丫123
初階會員


發表:85
回覆:62
積分:29
註冊:2004-08-31

發送簡訊給我
#4 引用回覆 回覆 發表時間:2004-11-08 15:06:28 IP:218.64.xxx.xxx 未訂閱
wameng果然厉害啊!高手高手啊
系統時間:2024-07-02 12:40:58
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!