Pascal:项目提升外部:SIGSEGV与Form交互时

时间:2016-01-28 18:13:22

标签: lazarus freepascal sigsegv

假设项目中有3个表单(Form1,Form2,Form3)。 Form1上有一个按钮,OnClick事件设置为Form2.Show。这段代码执行得很完美,但是如果Form2的代码试图调用Form3.Show,那么项目会引发一个EXTERNAL:SIGSEGV指向Customform.inc

  

项目project1引发了异常类'External:SIGSEGV'

     

在第2196行的文件'。\ include \ customform.inc'中:

     

可见:=真;

这正是我的项目正在发生的事情。所有表格都已正确创建和声明,单位完美链接。编译顺利,没有任何错误或警告。

因此不可能使第三种形式可见。但我发现每种交互都会导致一个External:SIGSEGV错误指向编译并运行得很好的随机代码片段。我只是无法弄清楚错误的起源。

如果我尝试在没有调试器的情况下执行我的项目,则会收到访问冲突错误。失败的代码:

procedure TWarForm.FormCreate(Sender: TObject);
Begin
   Form3.Show;
end;

unit work;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ExtCtrls,
  StdCtrls, BGRAFlashProgressBar, AuthUnit;

type

  { TWarForm }

  TWarForm = class(TForm)
    ArcaneDustIMG: TImage;
    ProgressBar: TBGRAFlashProgressBar;
    ArcaneEDT: TEdit;
    GoldEDT: TEdit;
    GoldIMG: TImage;
    Label1: TLabel;
    Wallpaper: TImage;
    procedure FormCreate(Sender: TObject);
    procedure WallpaperMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure WallpaperMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure WallpaperMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  WarForm: TWarForm;
  MouseIsDown: Boolean;
  PX, PY: Integer;

implementation

{$R *.lfm}

{ TWarForm }

procedure TWarForm.WallpaperMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  if Button = mbLeft then begin
    MouseIsDown := True;
    PX := X;
    PY := Y;
  end;
end;

procedure TWarForm.FormCreate(Sender: TObject);
Begin
   Form3.Show;
end;

procedure TWarForm.WallpaperMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  if MouseIsDown then begin
    SetBounds(WarForm.Left + (X - PX), WarForm.Top + (Y - PY), WarForm.Width, WarForm.Height);
  end;
end;

procedure TWarForm.WallpaperMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  MouseIsDown:=False;
end;

end.

1 个答案:

答案 0 :(得分:1)

您必须手动创建表单或在IDE中将其设置为“自动创建”

要手动创建它们只需稍微更改一下代码:

 TWarForm = class(TForm)
    ArcaneDustIMG: TImage;
    ProgressBar: TBGRAFlashProgressBar;
    ArcaneEDT: TEdit;
    GoldEDT: TEdit;
    GoldIMG: TImage;
    Label1: TLabel;
    Wallpaper: TImage;

    Form2: TForm2; // insert Form2
    Form3: TForm3; // and Form3

    procedure FormCreate(Sender: TObject);
    procedure WallpaperMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure WallpaperMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure WallpaperMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    { private declarations }
  public
    { public declarations }
  end;

  ..

  procedure TWarForm.FormCreate(Sender: TObject);
  Begin
    Form3 := TForm3.Create(Self);
    Form3.Show;
  end;    

如果您这样做,请不要忘记在应用程序执行结束时调用Form3.Free。