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



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.


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: Is C99 the final C? (some suggestions)
    ... >> defined a function that returns an image string for a value of your ... >> need to decide how and whether the user can define precedence for the ... > of declaration. ... "parenthesize, parenthesize, parenthesize". ...
    (comp.lang.c)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ... Its a concept from computer programming. ...
    (comp.lang.c)
  • Re: DhcpRequestParams from dhcpcsvc.dll
    ... it is because I do think that my own vb declaration is wrong, ... string to Unicode with StrConv and pass that as a string. ... Dim sendParams As DHCPAPI_PARAMS ...
    (microsoft.public.vb.winapi)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ...
    (comp.lang.c)
  • Re: curious about array initialization.
    ... understanding that its through the variable declaration that we ... By "inline string", I assume you mean a string literal. ... more than that you have implicit storage. ...
    (comp.lang.c)