这段程序有问题吗 bitmap创建了两次,为释放资源应该bitmap:=tbitmap.create;try ...finalybitmap.free;end; 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 (*//这段程序调试没有问题呀,我想看看全部的代码//*)//pasunit Unit1;interfaceuses Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Tabs;type TForm1 = class(TForm) ListBox1: TListBox; TabSet1: TTabSet; procedure FormCreate(Sender: TObject); procedure ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState); procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer); procedure TabSet1DrawTab(Sender: TObject; TabCanvas: TCanvas; R: TRect; Index: Integer; Selected: Boolean); procedure TabSet1MeasureTab(Sender: TObject; Index: Integer; var TabWidth: Integer); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);var Bitmap: TBitmap;begin ListBox1.Items := Screen.Fonts; Bitmap := TBitmap.Create; Bitmap.LoadFromFile('FIRST.BMP'); TabSet1.Tabs.AddObject('FIRST', Bitmap); Bitmap := TBitmap.Create; Bitmap.LoadFromFile('LAST.BMP'); TabSet1.Tabs.AddObject('LAST', Bitmap);end;procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer; var Height: Integer);begin with ListBox1.Canvas do begin Font.Name := ListBox1.Items[index]; Height := TextHeight('a'); end;end;procedure TForm1.TabSet1MeasureTab(Sender: TObject; Index: Integer; var TabWidth: Integer);var BitmapWidth: Integer;begin BitmapWidth := TBitmap(TabSet1.Tabs.Objects[Index]).Width; //这句有问题,去掉它程序正常 Inc(TabWidth, 2 + BitmapWidth);end;procedure TForm1.TabSet1DrawTab(Sender: TObject; TabCanvas: TCanvas; R: TRect; Index: Integer; Selected: Boolean);var Bitmap: TBitMap;begin Bitmap := TBitMap(TabSet1.Tabs.Objects[Index]); with TabSet1.Canvas do begin Draw(R.Left, R.Top + 4, Bitmap); TextOut(R.Left + 2 + Bitmap.Width, R.Top + 2, TabSet1.Tabs[index]); end;end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);begin with ListBox1.Canvas do begin FillRect(Rect); Font.Name := ListBox1.Items[index]; TextOut(Rect.Left, Rect.Top, ListBox1.Items[index]); end;end;end.//dfmobject Form1: TForm1 Left = 135 Top = 77 Width = 544 Height = 375 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False OnCreate = FormCreate PixelsPerInch = 96 TextHeight = 13 object ListBox1: TListBox Left = 0 Top = 65 Width = 536 Height = 283 Align = alClient ItemHeight = 16 Style = lbOwnerDrawVariable TabOrder = 0 OnDrawItem = ListBox1DrawItem OnMeasureItem = ListBox1MeasureItem end object TabSet1: TTabSet Left = 0 Top = 0 Width = 536 Height = 65 Align = alTop Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] Style = tsOwnerDraw OnDrawTab = TabSet1DrawTab OnMeasureTab = TabSet1MeasureTab endend 你改成这样试试procedure TForm1.FormCreate(Sender: TObject);var Bitmap:TBitMap;beginListBox1.Items:=Screen.Fonts;Bitmap:=TBitMap.Create ;Bitmap.LoadFromFile('FIRST.BMP');TabSet1.Tabs.AddObject('first',pointer(Bitmap));Bitmap:=TBitMap.Create ;Bitmap.LoadFromFile('LAST.BMP');TabSet1.Tabs.AddObject('last',pointer(Bitmap));end; of couse it just have two problems. [Error] Unit1.pas(30): Incompatible types: 'String' and 'Char' Borland 公司的前途以及 Delphi 前途 我编写的软件连接不上网络了 今天生日,散分 如何将word模板文件放入资源文件中,又如何从资源文件中提取这个模板文件? 在线等,mediaplayer 控件怎么判断已经播放结束?急! 怎样判断打印机的状态? 请教数据库问题 几个菜鸟级问题,请勿见笑!:) 问个buffer问题 寻求工业控制的控件,就是各种仪表,guage.... BatchMove问题,请高手指教!
这段程序调试没有问题呀,我想看看全部的代码
//*)//pasunit Unit1;interfaceuses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls, Tabs;type
TForm1 = class(TForm)
ListBox1: TListBox;
TabSet1: TTabSet;
procedure FormCreate(Sender: TObject);
procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
procedure TabSet1DrawTab(Sender: TObject; TabCanvas: TCanvas; R: TRect;
Index: Integer; Selected: Boolean);
procedure TabSet1MeasureTab(Sender: TObject; Index: Integer;
var TabWidth: Integer);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
var
Bitmap: TBitmap;
begin
ListBox1.Items := Screen.Fonts;
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('FIRST.BMP');
TabSet1.Tabs.AddObject('FIRST', Bitmap);
Bitmap := TBitmap.Create;
Bitmap.LoadFromFile('LAST.BMP');
TabSet1.Tabs.AddObject('LAST', Bitmap);
end;procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
var Height: Integer);
begin
with ListBox1.Canvas do
begin
Font.Name := ListBox1.Items[index];
Height := TextHeight('a');
end;
end;procedure TForm1.TabSet1MeasureTab(Sender: TObject; Index: Integer;
var TabWidth: Integer);
var
BitmapWidth: Integer;
begin
BitmapWidth := TBitmap(TabSet1.Tabs.Objects[Index]).Width; //这句有问题,去掉它程序正常
Inc(TabWidth, 2 + BitmapWidth);
end;procedure TForm1.TabSet1DrawTab(Sender: TObject; TabCanvas: TCanvas;
R: TRect; Index: Integer; Selected: Boolean);
var
Bitmap: TBitMap;
begin
Bitmap := TBitMap(TabSet1.Tabs.Objects[Index]);
with TabSet1.Canvas do
begin
Draw(R.Left, R.Top + 4, Bitmap);
TextOut(R.Left + 2 + Bitmap.Width, R.Top + 2, TabSet1.Tabs[index]);
end;
end;procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
begin
with ListBox1.Canvas do
begin
FillRect(Rect);
Font.Name := ListBox1.Items[index];
TextOut(Rect.Left, Rect.Top, ListBox1.Items[index]);
end;
end;end.//dfm
object Form1: TForm1
Left = 135
Top = 77
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
OnCreate = FormCreate
PixelsPerInch = 96
TextHeight = 13
object ListBox1: TListBox
Left = 0
Top = 65
Width = 536
Height = 283
Align = alClient
ItemHeight = 16
Style = lbOwnerDrawVariable
TabOrder = 0
OnDrawItem = ListBox1DrawItem
OnMeasureItem = ListBox1MeasureItem
end
object TabSet1: TTabSet
Left = 0
Top = 0
Width = 536
Height = 65
Align = alTop
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
Style = tsOwnerDraw
OnDrawTab = TabSet1DrawTab
OnMeasureTab = TabSet1MeasureTab
end
end
procedure TForm1.FormCreate(Sender: TObject);
var Bitmap:TBitMap;
begin
ListBox1.Items:=Screen.Fonts;
Bitmap:=TBitMap.Create ;
Bitmap.LoadFromFile('FIRST.BMP');
TabSet1.Tabs.AddObject('first',pointer(Bitmap));
Bitmap:=TBitMap.Create ;
Bitmap.LoadFromFile('LAST.BMP');
TabSet1.Tabs.AddObject('last',pointer(Bitmap));end;