帕斯卡 - 回复:用途

发布于 2024-07-16 08:19:41 字数 2190 浏览 14 评论 0原文

我有以下程序,它几乎可以工作,但当我尝试编译时产生以下错误,我不知道如何修复它! 有任何想法吗?

表单,'mainform.pas' 中的 mainform...

“unit1.pas(9): , 或 ; 预期但找到 'IN'; “project1 无法编译unit1.pas

    unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Dialogs, LibXmlParser, LibXmlComps, StdCtrls,
  Forms,
  mainform in 'mainform.pas'
  mapimail in 'mapimail.pas';

type
  TXMLRule = Record
    alert, desc, act:string;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    EasyXmlScanner1: TEasyXmlScanner;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Parser : TXmlParser;
  MyXMLRules:Array[1..10] of TXMLRule;
  i         :1..10;

implementation
{$R *.dfm}

procedure ProcessXML();

begin
  Parser := TXmlParser.Create;
  Parser.Normalize := TRUE;
  Parser.LoadFromFile ('c:\parser.xml');
  Parser.StartScan;

  while Parser.Scan do
    case Parser.CurPartType of
     ptStartTag,
     ptEmptyTag :
      begin

      end;

    ptContent  :
      begin
        if Parser.CurName = ('<alert>') then MyXMLRules[1].alert := Parser.CurContent;
        if Parser.CurName = ('<desc>') then MyXMLRules[1].desc := Parser.CurContent;
        if Parser.CurName = ('<action>') then MyXMLRules[1].act := Parser.Curcontent;
      end;
    end;
  Parser.Free;
end;

procedure EmailAlert();
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end;

procedure NoiseAlert();
begin
end;

procedure TForm1.Button1Click(Sender: TObject);
var
f:textFile;
data:string;
begin
   ProcessXML();

    AssignFile(f, 'c:\nmap.txt');
    reset(f);
    repeat
      readln(f, data);
      if (pos(MyXMLRules[1].alert, data)) <> 0 then

        begin
           if MyXMLRules[1].act
           = ('Email') then
                      begin
                        EmailAlert
                      end;
           if MyXMLRules[1].act
           = ('Beep') then
                      begin
                        NoiseAlert
                      end;
        end;
      until EOF(f);
end;

end.

I have the following program which very nearly works but is producing the following error when I try and compile, I have no idea how to fix it! any ideas?

Forms, mainform in 'mainform.pas'...

"unit1.pas(9): , or ; expected but 'IN' found;
"project1 could not compile unit1.pas

    unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls,
  Dialogs, LibXmlParser, LibXmlComps, StdCtrls,
  Forms,
  mainform in 'mainform.pas'
  mapimail in 'mapimail.pas';

type
  TXMLRule = Record
    alert, desc, act:string;
  end;

  TForm1 = class(TForm)
    Button1: TButton;
    EasyXmlScanner1: TEasyXmlScanner;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Parser : TXmlParser;
  MyXMLRules:Array[1..10] of TXMLRule;
  i         :1..10;

implementation
{$R *.dfm}

procedure ProcessXML();

begin
  Parser := TXmlParser.Create;
  Parser.Normalize := TRUE;
  Parser.LoadFromFile ('c:\parser.xml');
  Parser.StartScan;

  while Parser.Scan do
    case Parser.CurPartType of
     ptStartTag,
     ptEmptyTag :
      begin

      end;

    ptContent  :
      begin
        if Parser.CurName = ('<alert>') then MyXMLRules[1].alert := Parser.CurContent;
        if Parser.CurName = ('<desc>') then MyXMLRules[1].desc := Parser.CurContent;
        if Parser.CurName = ('<action>') then MyXMLRules[1].act := Parser.Curcontent;
      end;
    end;
  Parser.Free;
end;

procedure EmailAlert();
begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end;

procedure NoiseAlert();
begin
end;

procedure TForm1.Button1Click(Sender: TObject);
var
f:textFile;
data:string;
begin
   ProcessXML();

    AssignFile(f, 'c:\nmap.txt');
    reset(f);
    repeat
      readln(f, data);
      if (pos(MyXMLRules[1].alert, data)) <> 0 then

        begin
           if MyXMLRules[1].act
           = ('Email') then
                      begin
                        EmailAlert
                      end;
           if MyXMLRules[1].act
           = ('Beep') then
                      begin
                        NoiseAlert
                      end;
        end;
      until EOF(f);
end;

end.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

假装爱人 2024-07-23 08:19:41

您在第 9 行(带有“mainform in 'mainform.pas'”的行)末尾缺少一个逗号。

You're missing a comma at the end of line 9 (the line with "mainform in 'mainform.pas'").

最偏执的依靠 2024-07-23 08:19:41

根据Delphi Basics,“in”仅适用于程序和图书馆而不是单位。

According to Delphi Basics the "in" is only applicable to programs and libraries and not units.

断念 2024-07-23 08:19:41

您正在混合单元代码和项目代码。

在 Delphi(和 freepascal)中,项目文件 (.dpr) 允许您通过指定操作系统文件来包含自定义源文件(通常是您的单元)。 这用于通知编译器不要寻找预编译单元。

project MyApp;

uses
  forms,
  unit1 in 'unit1.pas';

正如您所提供的,作为一个单位,您不能这样做。

删除 IN 和带引号的字符串,只要清除代码中的其余错误就应该没问题。

You're mixing unit code and project code.

In Delphi (and freepascal), a project file (.dpr) allows you to include custom source files, usually your units, by specifying a OS file. This is used to notify the compiler not to look for a pre-compiled unit.

project MyApp;

uses
  forms,
  unit1 in 'unit1.pas';

Where as a unit, as you've provided, you can not do this.

Remove the IN and the quoted strings and you should be fine as long as you clean up the rest of the errors in the code.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文