Pascal - Re:使用

时间:2009-03-25 15:50:39

标签: xml parsing pascal

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

表单,'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.

3 个答案:

答案 0 :(得分:3)

你在第9行的末尾('mainform.pas'中的“mainform”行)中缺少逗号。

答案 1 :(得分:2)

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

答案 2 :(得分:1)

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

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

project MyApp;

uses
  forms,
  unit1 in 'unit1.pas';

如你所提供的那样,你不能这样做。

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