M
mylovegirl
Unregistered / Unconfirmed
GUEST, unregistred user!
下面的程序怪了,运行完关闭窗口时,提示无效的指针操作,各位看看是哪儿的问题
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
DrawGrid1: TDrawGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
Function GetBinStr(var H,W:integer):integer;
{ Public declarations }
end;
var
Form1: TForm1;
Bmp:TBitmap;
S:Array of Array of Integer;
Wth,Hgh:integer;
implementation
{$R *.dfm}
Function TForm1.GetBinStr(var H,W:integer):integer;
var
X,Y:Integer;
begin
for Y:=0 to H-1 do
for X:=0 to W-1 do
begin
if Bmp.Canvas.Pixels[X,Y]=0 then
S[Y,X]:=1
else
S[Y,X]:=0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Str:string;
begin
Bmp:=TBitmap.Create;
Str:=Edit1.Text;
try
Bmp.Width:=800;
Bmp.Height:=100;
Bmp.PixelFormat:=pf1bit;
with Bmp.Canvas do
begin
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(ClipRect);
Font:=Edit1.Font;
Textout(0,0,Str);
Wth:=textwidth(Str); //求出字宽
Hgh:=textheight(Str); //求出字高
setlength(S,Hgh,Wth);
GetBinStr(Wth,Hgh);
end;
finally
Bmp.free;
end;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Button2: TButton;
DrawGrid1: TDrawGrid;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
Function GetBinStr(var H,W:integer):integer;
{ Public declarations }
end;
var
Form1: TForm1;
Bmp:TBitmap;
S:Array of Array of Integer;
Wth,Hgh:integer;
implementation
{$R *.dfm}
Function TForm1.GetBinStr(var H,W:integer):integer;
var
X,Y:Integer;
begin
for Y:=0 to H-1 do
for X:=0 to W-1 do
begin
if Bmp.Canvas.Pixels[X,Y]=0 then
S[Y,X]:=1
else
S[Y,X]:=0;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Str:string;
begin
Bmp:=TBitmap.Create;
Str:=Edit1.Text;
try
Bmp.Width:=800;
Bmp.Height:=100;
Bmp.PixelFormat:=pf1bit;
with Bmp.Canvas do
begin
Brush.Color:=clWhite;
Brush.Style:=bsSolid;
FillRect(ClipRect);
Font:=Edit1.Font;
Textout(0,0,Str);
Wth:=textwidth(Str); //求出字宽
Hgh:=textheight(Str); //求出字高
setlength(S,Hgh,Wth);
GetBinStr(Wth,Hgh);
end;
finally
Bmp.free;
end;
end;
end.