Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 21st, 2006, 11:01 PM   #1
Liens
Newbie
 
Join Date: Jan 2006
Posts: 6
Rep Power: 0 Liens is on a distinguished road
Multiple Units and Records

Hi, I looked around a bit, but I couldn't find anything to answer my question.
When I am trying to use two units, I declare a record in the first one, say an integer and a string, called IntStr. Then I have a procedure in the second unit that uses the record decalred in the first unit, I want to use the procedure declared in the second unit, in the first unit(I can do this part), so I can send a variable of type IntStr to the second form(Can't do this part).

I tried re-declaring the record in the second unit, but delphi thinks they are two different types of records so it gives me a type mismatch error.
Liens is offline   Reply With Quote
Old Jan 22nd, 2006, 4:38 AM   #2
Carl
Newbie
 
Join Date: Sep 2004
Location: Chelmsford, Essex, UK
Posts: 28
Rep Power: 0 Carl is on a distinguished road
Send a message via MSN to Carl
Very hard to say without seeing your code. You declared the record in the first unit which you then want to pass to a procedure in the second unit?

If I'm right then it's all to do with your "uses" position. You need to make sure that the first unit is listed in the "uses" BEFORE the procedure is declared in the second unit. That way the compiler will know what the data type is.

Carl
__________________
Software developer since 1982, started on a ZX81.
Been developing in Delphi since 1998.
Currently trying to get my head round C++.
Carl is offline   Reply With Quote
Old Jan 22nd, 2006, 6:06 AM   #3
Liens
Newbie
 
Join Date: Jan 2006
Posts: 6
Rep Power: 0 Liens is on a distinguished road
//---------------------------Unit1-------------------------//
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, StrUtils, Variants, Classes, Graphics, Controls,
  Forms, Dialogs, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

Uses Unit2;

{$R *.dfm}
Type IntStr =
  Record
    Integer: Integer;
    String: String;
  End;

procedure TForm1.FormCreate(Sender: TObject);
Var VariableToSend: IntStr;

begin
  SoupUnit.Soup(VariableToSend);
end;

//----------------------------Unit2-----------------------------//
unit Unit2;

interface

uses
  Forms, Unit1;

type
  TSoupUnit = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
    procedure Soup(VariableToRecieve: IntStr);
  end;

var
  SoupUnit: TSoupUnit;

implementation

Procedure TSoupUnit.Soup(VariableToRecieve: IntStr);
Begin
  With VariableToRecieve do
    Blah blah...
End;

Theres a basic breakdown of what I'm trying to achieve, it keeps telling me that IntStr is an Undeclared Identifier
Liens is offline   Reply With Quote
Old Jan 22nd, 2006, 6:28 AM   #4
Carl
Newbie
 
Join Date: Sep 2004
Location: Chelmsford, Essex, UK
Posts: 28
Rep Power: 0 Carl is on a distinguished road
Send a message via MSN to Carl
Type IntStr =
  Record
    Integer: Integer;
    String: String;
  End;
Try moving the declaration before the "implementation" section, ie immediately under the type definition of the form in unit 1. From what I understand, anything under "implementation" refers to the local unit.

type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Type IntStr =
  Record
    Integer: Integer;
    String: String;
  End;

var
  Form1: TForm1;

implementation


Carl
__________________
Software developer since 1982, started on a ZX81.
Been developing in Delphi since 1998.
Currently trying to get my head round C++.
Carl is offline   Reply With Quote
Old Jan 22nd, 2006, 7:07 AM   #5
Liens
Newbie
 
Join Date: Jan 2006
Posts: 6
Rep Power: 0 Liens is on a distinguished road
Thanks buddy, that works just how I needed it, and now I know what the implementation thing was for, I always kinda wondered.
Liens is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 10:47 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC