views:

195

answers:

3

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.
+4  A: 

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

Björn
That's true but I don't think the parser has got that far yet.
RobS
Yeah, you're probably right. I haven't touched Pascal in over 6 years so I'm a bit rusty. ;)
Björn
+2  A: 

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

RobS
of course thanks. do you know what can be used instead?
Just remove the "in filename" part and see if that works?
RobS
Otherwise extend the search path, either for Delphi or only the project, or add the mainform.pas to the dpr.
Ralph Rickenbach
Im not using a .dpr its a form that compiles when I click the button
ignore that moronic statement actually..
+1  A: 

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.

Ryan J. Mills