EReadError - 当我尝试创建 Delphi 单元时无效的属性值

Joh*_*ony 2 delphi

我正在尝试创建并运行新的 Delphi 应用程序。但是在下面的项目文件中,当我尝试 CreateForm 时出现此错误:调试器异常:项目...引发异常类 EReadError 并带有消息无效属性值。过程停止。

program Project1;

uses
  Forms,
  OCR in 'OCR.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.Title := 'OCR';
  Application.CreateForm(TForm1, OCR1);
  Application.Run;
end.
Run Code Online (Sandbox Code Playgroud)

单元:

unit OCR;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs;

type
  TForm1 = class(TForm)
  private
  public
    procedure FormCreate(Sender: TObject);
  end;

var
  OCR1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
var list: TStringList;
begin
list := TStringList.create;
list.loadFromFile('OCR.txt');

end;

end.
Run Code Online (Sandbox Code Playgroud)

DFM 文件:

object Form1: TForm1
  Left = 210
  Top = 181
  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
end
Run Code Online (Sandbox Code Playgroud)

我尝试运行 FormCreate 函数。我所做的是在 Object Inspector -> Form1 ... Events ... 我设置了 OnCreate: FormCreate。这是在 Delphi 7 上创建的。这里有什么问题?

但是这个错误发生了。

Dav*_*nan 5

需要发布事件处理程序,以便流式框架找到它们。您需要声明FormCreate为 aspublished而不是public