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

Delphi轉成BCB程式..

答題得分者是:chtai
pika2005
初階會員


發表:27
回覆:48
積分:25
註冊:2005-02-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2005-03-19 21:18:19 IP:218.162.xxx.xxx 未訂閱
大家好,小弟要把以下程式轉成BCB..而紅色內容是我改寫的..但是還是有錯.. Error Message:Call to undefined function 'Inc'.. 請問使用Inc函數,要引用那個.h檔..    combobox中下拉後的內容不夠寬 http://delphi.ktop.com.tw/topic.php?topic_id=24612    
 
procedure SetComboDropDownWidth(ComboBox: TComboBox; Width: Longint = -1); 
var 
  I, TextLen: Longint; 
begin 
  if Width < ComboBox.Width then 
  begin 
    ComboBox.Canvas.Handle := GetDC(ComboBox.Handle); 
    try 
      for I := 0 to ComboBox.Items.Count -1 do 
      begin 
        TextLen := ComboBox.Canvas.TextWidth(ComboBox.Items[I]); 
        if TextLen > Width then 
          Width := TextLen; 
      end;           (* Standard ComboBox drawing is Rect.Left   2, 
         adding the extra spacing offsets this *) 
      Inc(Width, 10); 
    finally 
      ReleaseDC(ComboBox.Handle, ComboBox.Canvas.Handle); 
    end; 
  end; 
  SendMessage(ComboBox.Handle, CB_SETDROPPEDWIDTH, Width, 0); 
end;
 

void __fastcall SetComboDropDownWidth(TComboBox *ComboBox1,int Width)
{
  int I,TextLen;
  ShowMessage("1");
  if(Width < ComboBox1->Width)
  {
    ComboBox1->Canvas->Handle = GetDC(ComboBox1->Handle);
    __try
    {
      for(I = 0;I < ComboBox1->Items->Count-1;I  )
      {
        AnsiString data = ComboBox1->Items->Strings[I].SubString(0,100);
        TextLen = ComboBox1->Canvas->TextWidth(data);
        if(TextLen > Width)
          Width = TextLen;
      }          /*(* Standard ComboBox drawing is Rect.Left   2,
         adding the extra spacing offsets this *)
      */
      Inc(Width, 10);
    }
      __finally
      {
        ReleaseDC(ComboBox1->Handle,ComboBox1->Canvas->Handle);
      }
  }
  SendMessage(ComboBox1->Handle, CB_SETDROPPEDWIDTH, Width, 0);
}    
chtai
高階會員


發表:68
回覆:238
積分:116
註冊:2004-05-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2005-03-19 21:59:00 IP:203.67.xxx.xxx 未訂閱
引言:
 
      for(I = 0;I < ComboBox1->Items->Count-1;I  )
      {
       ...............
      }
      Inc(Width, 10);
應該是
 for(I = 0; I < ComboBox1->Items->Count; I  )
而不是 Count-1 另, Inc(Width, 10); 就是 Width = 10; 啦 --
------
My Web: http://nelson.csie.us
My Blog: http://blog.nelson.csie.us
系統時間:2024-06-29 17:58:05
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!