sudhakar_koundinya
asked on
How to create the unnamed unions and structures in delphi?
Hi all,
How to create the unnamed unions and structures in delphi
for e.g.
struct
{
int i;
double x;
char* str;
};
union
{
int i;
double x;
char* str;
struct someVatiable;
};
thanks
Koundinya
How to create the unnamed unions and structures in delphi
for e.g.
struct
{
int i;
double x;
char* str;
};
union
{
int i;
double x;
char* str;
struct someVatiable;
};
thanks
Koundinya
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The above is wrong even in C.
ASKER
i agree with u, but this works in c++
struct MyStruct
{
union
{
int booln;
int intg;
double real;
int blk;
};
};
class MyClass
{
union {
int intg;
double real;
char *name;
char *cmd;
};
};
struct MyStruct
{
union
{
int booln;
int intg;
double real;
int blk;
};
};
class MyClass
{
union {
int intg;
double real;
char *name;
char *cmd;
};
};
well, don't know waht union means,
but here some possibilities
TRecord = Record
a : Integer;
b : String;
end;
TOtherRecord = Record
a : Integer;
b : String;
c : TRecord;
end;
TAnotherOneRecord = Record
a : Integer;
b : String;
c : TRecord;
d : Record
a : Integer;
b : String;
end;
end;
meikl ;-)
but here some possibilities
TRecord = Record
a : Integer;
b : String;
end;
TOtherRecord = Record
a : Integer;
b : String;
c : TRecord;
end;
TAnotherOneRecord = Record
a : Integer;
b : String;
c : TRecord;
d : Record
a : Integer;
b : String;
end;
end;
meikl ;-)
The easiest way in Delphi is to make the union its own full variant record. Then it needs of course its own type name.
It is bad style anyway to use unnamed structures.
It is bad style anyway to use unnamed structures.
union is a record with variant part.
>union is a record with variant part.
? something like
type
TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);
TFigure = record
case TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
just pasted from the delphi-online-help
? something like
type
TShapeList = (Rectangle, Triangle, Circle, Ellipse, Other);
TFigure = record
case TShapeList of
Rectangle: (Height, Width: Real);
Triangle: (Side1, Side2, Angle: Real);
Circle: (Radius: Real);
Ellipse, Other: ();
end;
just pasted from the delphi-online-help
to use variant records of course:
type
TEmployee = record
FirstName, LastName: string[40];
BirthDate: TDate;
case Salaried: Boolean of
True: (AnnualSalary: Currency);
False: (HourlyWage: Currency);
end;
AnnualSalary and HourlyWage will be share the same physical memory, so it will be identical to C union
type
TEmployee = record
FirstName, LastName: string[40];
BirthDate: TDate;
case Salaried: Boolean of
True: (AnnualSalary: Currency);
False: (HourlyWage: Currency);
end;
AnnualSalary and HourlyWage will be share the same physical memory, so it will be identical to C union
someone else, who looks in the delphi online help, or, stepashka?
ASKER
:-)
Hmmm... RTFM is my motto! Read the F@#$ing Manual (sorry)
LOLROF
:( I'll never read the help and cite it...
ASKER
Acceping your answer, as i agree with ur first comment