![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jan 2006
Posts: 6
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Newbie
|
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++. |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Jan 2006
Posts: 6
Rep Power: 0
![]() |
//---------------------------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 |
|
|
|
|
|
#4 |
|
Newbie
|
Type IntStr =
Record
Integer: Integer;
String: String;
End;type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;
Type IntStr =
Record
Integer: Integer;
String: String;
End;
var
Form1: TForm1;
implementationCarl
__________________
Software developer since 1982, started on a ZX81. Been developing in Delphi since 1998. Currently trying to get my head round C++. |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Jan 2006
Posts: 6
Rep Power: 0
![]() |
Thanks buddy, that works just how I needed it, and now I know what the implementation thing was for, I always kinda wondered.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|