Re: having difficulty getting the unit to use an include file




Rob Kennedy wrote:
> Adam Sandler wrote:
> > But first, here's the contents of my include file:
> >
> > type
> > mailingListRecord = record
> > givenName : string;
> > familyName : string;
> > address : string;
> > city : string;
> > state : string;
> > postalCode : Integer;
> > end;
>
> OK. Note that the file contains a type declaration. A type declaration.
> Remember that for later.
>
> > And here's the unit file:
> >
> > unit IncludeExample;
> >
> > interface
> >
> > uses
> > Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
> > Dialogs,
> > StdCtrls;
> >
> > {$I RecordExample.inc}
>
> If it would help you, just copy the contents of RecordExample.inc and
> paste them into this file, in place of the $I directive. That's all the
> compiler does, after all. Seeing the text of your unit the same as the
> compiler sees it might help you notice the error.

Thanks for the advice... I did this and it showed me where I was going
wrong. Thanks again!

> > type
> > TForm1 = class(TForm)
> > myMemo: TMemo;
> > procedure FormCreate(Sender: TObject);
> > private
> > { Private declarations }
> > public
> > { Public declarations }
> > end;
> >
> > var
> > Form1: TForm1;
>
> So the interface section of the IncludeExample unit contains three
> things: A record-type declaration for mailingListRecord, a class-type
> declaration for TForm1, and a variable declaration for Form1.
>
> > implementation
> >
> > {$R *.DFM}
> >
> > procedure TForm1.FormCreate(Sender: TObject);
> >
> > begin
> > mailingListRecord.givenName := 'joe';
>
> You can't assign values to types. Remember what mailingListRecord is?
>
> > myMemo.Lines.Clear;
> > myMemo.Lines.Add(mailingListRecord.givenName);
> > end;
> >
> > end.
> >
> > At first I though the problem was because I didn't declare the record.
> > But that wasn't it because if I put mailingListRecord :
> > TMailingListRecord; in the interface section, I get a identifier
> > redeclared error.
>
> Of course. You've already declared "mailingListRecord" to be the name of
> a type. I have no idea what "TMailingListRecord" is, and neither does
> the compiler.
>
> > When I try to send text to any of the strings
> > declared in the record, I get an error stating object or class type
> > required.
>
> Yep.
>
> --
> Rob

.



Relevant Pages

  • Re: having difficulty getting the unit to use an include file
    ... Rob Kennedy wrote: ... Note that the file contains a type declaration. ... > compiler sees it might help you notice the error. ... Remember what mailingListRecord is? ...
    (comp.lang.pascal.delphi.misc)
  • Re: having difficulty getting the unit to use an include file
    ... familyName: string; ... compiler sees it might help you notice the error. ... A record-type declaration for mailingListRecord, ... declaration for TForm1, and a variable declaration for Form1. ...
    (comp.lang.pascal.delphi.misc)
  • Re: Question about multiple files
    ... No. extern just means: The actual definition is somewhere else. ... the compiler can differentiate between declaration and definition just ... > declaration it finds and in this way can I write code expecting it to be ... When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Question about multiple files
    ... but say I declare with extern. ... > the compiler can differentiate between declaration and definition just ... >> declaration it finds and in this way can I write code expecting it to be ... > When the compiler reaches the line foo(); ...
    (alt.comp.lang.learn.c-cpp)
  • Re: Cpp Considered Harmful
    ... >> programming language, the compiler, the IDE, the libraries, etc. ... source file, the implementation shall locate the declaration, (and ... to name one of the defining source files on the command line that initiates ... The counterpart to this in Java is accomplished using the following: ...
    (comp.lang.cpp)