报错:project 程序名  raised exception class EAccessVilation with message 'Access vilation at address 004045AB in module 'ag.exe'Read of address 000000'.Process stopped附上代码: 最后注明出错位置
unit UnitDisplay;interfaceuses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ExtCtrls, Menus, jpeg, Math, StdCtrls, ComCtrls, dblookup, DBCtrls;type
  Scale = record
    Xmin: integer;
    Xmax: integer;
    Ymin: integer;
    Ymax: integer;
  end;  TFormDataShow = class(TForm)
    MainMenu1: TMainMenu;
    File1: TMenuItem;
    Exit1: TMenuItem;
    N1: TMenuItem;
    PrintSetup1: TMenuItem;
    Print1: TMenuItem;
    N2: TMenuItem;
    SaveAs1: TMenuItem;
    Save1: TMenuItem;
    Open1: TMenuItem;
    New1: TMenuItem;
    Edit1: TMenuItem;
    Object1: TMenuItem;
    Links1: TMenuItem;
    N3: TMenuItem;
    GoTo1: TMenuItem;
    Replace1: TMenuItem;
    Find1: TMenuItem;
    N4: TMenuItem;
    PasteSpecial1: TMenuItem;
    Paste1: TMenuItem;
    Copy1: TMenuItem;
    Cut1: TMenuItem;
    N5: TMenuItem;
    Repeatcommand1: TMenuItem;
    Undo1: TMenuItem;
    Help1: TMenuItem;
    About1: TMenuItem;
    HowtoUseHelp1: TMenuItem;
    SearchforHelpOn1: TMenuItem;
    Contents1: TMenuItem;
    OpenDialog1: TOpenDialog;
    YaxisSelection : TComboBox;
    XaxisSelection : TComboBox;
    procedure FormPaint(Sender: TObject);
    procedure Open1Click(Sender: TObject);
    procedure YaxisSelectionChange(Sender: TObject);
    procedure XaxisSelectionChange(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;var
  FormDataShow: TFormDataShow;implementation{$R *.dfm}uses GDIPAPI, GDIPOBJ; // GdiPlus, GdiPlusHelpers;//GDIPAPI,GDIPOBJ;const
  AutoScale_MarginRatio = 0.12; // 做图时前后上下留出空白的比例var
  DataFilePath: String; // 数据文件地址
  Ydata: array of Double;
  Xdata: array of Double;
  Xdvdata: array of Double;
  Ydvdata: array of Double;
  Xtag: integer;
  Ytag: integer; // 先定义为整型,如何实现再说
  AutoScale: Boolean; // 自动缩放
  dataString: TStringList;
  headerText: TStringList;procedure ReadFile;
var
  AllinFile: TStringList; // 传递数据文件中所有字符,分割为文件头和文件数据,用完即销毁
begin
  AllinFile := TStringList.Create;
  // AllinFile.Delimiter := ' '+#13#10; //能这样吗?
  AllinFile.LoadFromFile(DataFilePath);  dataString := TStringList.Create;
  // dataString.Delimiter := #13#10;
  headerText := TStringList.Create;
  headerText.Delimiter := ',';
  headerText.DelimitedText := AllinFile[0];
  FormDataShow.YaxisSelection.Items := HeaderText;
  FormDataShow.YaxisSelection.ItemIndex := 1;
  FormDataShow.XaxisSelection.Items := HeaderText;
  FormDataShow.XaxisSelection.ItemIndex := 0;  Xtag :=  FormDataShow.XaxisSelection.ItemIndex;
  Ytag := FormDataShow.YaxisSelection.ItemIndex;  AllinFile.Delete(0);
  dataString := AllinFile; // header & data都只创建没销毁,每次调用此函数前必须先销毁!!!  //AllinFile.Destroy;
end;procedure DataSelection; // 选择并赋值X Y数组
var
  temp: TStringList;
  i: integer;
begin
/////////////////////////////////////////////
  //Xtag :=2;
  //Ytag :=4;
/////////////////////////////////////////////
  temp := TStringList.Create;
  temp.Delimiter := ',';
  SetLength(Xdata,datastring.Count);
  setlength(Ydata,datastring.count);
  // dataString.Delimiter := #13#10;
  for i := 0 to dataString.count - 1 do
  begin
    temp.DelimitedText := dataString[i];
    Xdata[i] := strtofloat(temp[Xtag]);
    Ydata[i] := strtofloat(temp[Ytag]);   //注意数组计数从零开始!
  end;
  temp.Free;
end;function getMaxValue(arr: array of Double): Double;
var
  i: integer;
begin
  result := arr[0];
  for i := 1 to Length(arr) - 1 do
  begin
    if arr[i] > result then
      result := arr[i];
  end;
end;function getMinValue(arr: array of Double): Double;
var
  i: integer;
begin
  result := arr[0];
  for i := 1 to Length(arr) - 1 do
  begin
    if arr[i] < result then
      result := arr[i];
  end;
end;
procedure TFormDataShow.FormPaint(Sender: TObject);
var
  ShowGraph: TGPGraphics;
  Brush: TGPSolidBrush;
  DataRegion: TGPRegion; // 定义画图区域
  ulOrigin, Origin, PaintPoint: TGPPoint;
  // 左上角,坐标原点  Width, Height,i,n,Nx,Ny: integer; // 画图区域的长边宽边
  dvx,dvy,iX0,iY0,iXm,iYm:Double;
  leftmost, rightmost, upmost, downmost, drawingXrange, drawingYrange: integer;
  Xleft, Xright, Ybottom, Ytop, Xrange, Yrange, X0, Y0,Xm,Ym : Double;
  XdisplayRatio, YdisplayRatio,XdisplayRange,YdisplayRange: Double;    // 像素/数据
  p: TGPPen;
  //PaintScale: Scale;begin
  ShowGraph := TGPGraphics.Create(Canvas.Handle);
  ShowGraph.Clear(aclWheat);
  Brush := TGPSolidBrush.Create(aclWhite);
  p := TGPPen.Create(MakeColor(255,0,0), 2);  ulOrigin.X := Ceil(FormDataShow.Width * 0.05);
  ulOrigin.Y := floor((FormDataShow.Height - 60) * 0.05);
  Width := floor(FormDataShow.Width * 0.9);
  Height := Ceil((FormDataShow.Height - 60) * 0.9);
  Origin.X := ulOrigin.X;
  Origin.Y := ulOrigin.Y + Height; //注意像素点的Y轴是跟数据的Y轴反过来的。  DataRegion := TGPRegion.Create(MakeRect(ulOrigin.X, ulOrigin.Y, Width,
      Height));
  ShowGraph.FillRegion(Brush, DataRegion);  //////////////////////////////////////////////
  AutoScale := True;
//  datafilepath := 'C:\Documents and Settings\ET\桌面\30nm H for mat.dat';
//  readfile;
//  dataselection;
  //////////////////////////////////////////////  if AutoScale {and (DataFilePath<>' ')} then
  begin
    Xleft := getMinValue(Xdata);
    Ybottom := getMinValue(Ydata);
    Xright := getMaxValue(Xdata);
    Ytop := getMaxValue(Ydata);
    Xrange := Xright - Xleft;
    Yrange := Ytop - Ybottom;
    if Xrange=0 then
      Xrange := 0.1;
    if Yrange=0 then
      Yrange := 0.1;
    XdisplayRange := Xrange/(1-AutoScale_MarginRatio);
    YdisplayRange := Yrange/(1-AutoScale_MarginRatio);    //显示的数据跨度。手动缩放之后更改此值。
    X0 := Xleft-AutoScale_MarginRatio*XdisplayRange/2;
    Y0 := Ybottom-AutoScale_MarginRatio*YdisplayRange/2;
    Xm := Xright+ AutoScale_MarginRatio*XdisplayRange/2;
    Ym := Ytop+AutoScale_MarginRatio*XdisplayRange/2;
    XdisplayRatio := Width/Xdisplayrange;
    YdisplayRatio := Height/Ydisplayrange;    for i := 0 to length(Xdata) - 1 do
    begin
      paintPoint.X := round(XdisplayRatio*(Xdata[i]-X0))+Origin.X;
      paintPoint.Y := Origin.Y-round(YdisplayRatio*(Ydata[i]-Y0));
      ShowGraph.DrawEllipse(p,paintpoint.X,paintpoint.Y,2,2);
    end;    {with PaintScale do
    begin
      Xmin := leftmost - round(AutoScale_MarginRatio / 2 * Xrange);
      Ymin := round(getMinValue(Ydata));
      Xmax := round(getMaxValue(Xdata));
      Ymax := round(getMaxValue(Ydata));
    end;   }
  end;  iX0:=1;
  iY0:=1;
  iXm:=1;
  iYm:=1;
  while Xm>100 do begin
    Xm := Xm/10;
    iXm:= iXm*10;
  end;
  while Ym>100 do begin
    Ym:= Ym/10;
    iYm:= iYm*10;
  end;
  while X0>100 do begin
    X0:= X0/10;
    iX0:= iX0*10;
  end;
  while Y0>100 do  begin
    Y0:= Y0/10;
    iYm:= iYm*10;
  end;  if iXm>=iX0 then
    X0:=X0*iX0/iXm;  if iYm>=iY0 then
    Y0:=Y0*iY0/iYm;  if Xm-X0>=60 then
    dvx := 10
  else
    if Xm-X0>=30 then
      dvx := 5
    else
      dvx :=2;  if Ym-Y0>=60 then
    dvy := 10
  else
    if Ym-Y0>=30 then
      dvy := 5
    else
      dvy :=2;  Nx:= floor((Xm-X0)/dvx);
  Ny:= floor((Ym-Y0)/dvy);
  SetLength(Xdvdata,Nx);
  setlength(Ydvdata,Ny);  for n := 1 to Nx  do
  begin
    Xdvdata[0] := floor(X0/dvx)*dvx;
    Xdvdata[n] := Xdvdata[n-1]+dvx;
  end;
  for n := 1 to Ny  do
  begin
    Ydvdata[0] := floor(Y0/dvy)*dvy;
    Ydvdata[n] := Ydvdata[n-1]+dvy;   //注意数组计数从零开始!
  end;
  for n := 0 to Nx - 1 do
    begin
      paintPoint.X := round(XdisplayRatio*(Xdvdata[n]*iXm-X0))+Origin.X;
      paintPoint.Y := Origin.Y-round(YdisplayRatio*(Ydvdata[0]*iYm-Y0));
      ShowGraph.DrawEllipse(p,paintpoint.X,paintpoint.Y,4,4);
    end;
  for n := 0 to Ny - 1 do
    begin
      paintPoint.X := round(XdisplayRatio*(Xdvdata[0]*iXm-X0))+Origin.X;
      paintPoint.Y := Origin.Y-round(YdisplayRatio*(Ydvdata[n]*iYm-Y0));
      ShowGraph.DrawEllipse(p,paintpoint.X,paintpoint.Y,4,4);
    end;  ShowGraph.DrawLine(p,Xdvdata[0],Ydvdata[0],Xdvdata[0],Ydvdata[Ny-1]);
  ShowGraph.DrawLine(p,Xdvdata[0],Ydvdata[0],Xdvdata[Nx-1],Ydvdata[0]);
// 上面两行 没有添加之前没有问题 加了之后出现错误~~ 球大神出现~
  Brush.Free;
  DataRegion.Free;
  ShowGraph.Free;
  p.Free;
 end;
procedure TFormDataShow.Open1Click(Sender: TObject);
begin
  if OpenDialog1.Execute then
  begin
    DataFilePath := OpenDialog1.FileName;
    ReadFile;
    dataselection;
    FormDataShow.FormPaint(sender);
  end;
end;
procedure TFormDataShow.XaxisSelectionChange(Sender: TObject);
begin
  Xtag := XaxisSelection.ItemIndex;
  DataSelection;
  FormPaint(sender);
end;procedure TFormDataShow.YaxisSelectionChange(Sender: TObject);
begin
  Ytag := YaxisSelection.ItemIndex;
  DataSelection;
  FormPaint(sender);
end;end.