帕斯卡 - 回复:用途
我有以下程序,它几乎可以工作,但当我尝试编译时产生以下错误,我不知道如何修复它! 有任何想法吗?
表单,'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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您在第 9 行(带有“mainform in 'mainform.pas'”的行)末尾缺少一个逗号。
You're missing a comma at the end of line 9 (the line with "mainform in 'mainform.pas'").
根据Delphi Basics,“in”仅适用于程序和图书馆而不是单位。
According to Delphi Basics the "in" is only applicable to programs and libraries and not units.
您正在混合单元代码和项目代码。
在 Delphi(和 freepascal)中,项目文件 (.dpr) 允许您通过指定操作系统文件来包含自定义源文件(通常是您的单元)。 这用于通知编译器不要寻找预编译单元。
正如您所提供的,作为一个单位,您不能这样做。
删除 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.
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.