Board index » delphi » TEdit..Display user defined Types

TEdit..Display user defined Types

I have the following as part of my data structure:

type
  Status:(Active,InActive);

  StudentRecord = packed record
                   StatusOfStudent: Status;
  end;

Now how do I  display a Status in TEdit ?

Thanks,
Linden

 

Re:TEdit..Display user defined Types


In article <39C04DFA.40B2...@telusplanet.net>, Linden Willms

Quote
<lwil...@telusplanet.net> writes:
>I have the following as part of my data structure:

>type
>  Status:(Active,InActive);

>  StudentRecord = packed record
>                   StatusOfStudent: Status;
>  end;

>Now how do I  display a Status in TEdit ?

As Status is an alternate value (either one or the other) then you are better
using a boolean value and displaying it in a CheckBox.

// displaying
MyCheckBox.Checked := StatusOfStudent;
// storing
StatusOfStudent := MyCheckBox.Cheacked;

For any constrained multiple choice it is better _not_ to use a free text entry
component (ie a TEdit). Use a combo-box or listbox and store the ItemIndex cast
to the choice type.

If you want to display in a label then use an array of string :-

StatusStr : array[Active..InActive of string = ('Active', 'InActive');

MyLabel.Caption := StatusStr[StatusOfStudent];

BTW your code will be clearer if you comply with Delphi naming conventions :-

type
  TStatus:(sActive, sInActive); // type prefixed with 'T', values prefixed with
initial of name(s)

  TStudentRecord = packed record
    StatusOfStudent: Status;
  end;

Alan Lloyd
alangl...@aol.com

Re:TEdit..Display user defined Types


Linden

the following should work...

var Student : StudentRecord ;

with Student do
begin
...
// read/set StatusOfStudent
if (StatusOfStudent=Active) then Edit1.Text:='Active'
else Edit1.Text:='Inactive' ;
...
end ;

Regards

Joseph

Quote
Linden Willms wrote:
> I have the following as part of my data structure:

> type
>   Status:(Active,InActive);

>   StudentRecord = packed record
>                    StatusOfStudent: Status;
>   end;

> Now how do I  display a Status in TEdit ?

> Thanks,
> Linden

Re:TEdit..Display user defined Types


You have loads of options:

begin
  if StatusOfStudent = Active then
    Edit1.Text := 'Active'
  else
    Edit1.Text := 'Inactive';
end;

or

begin
  case StatusOfStudent of
    Active: Edit1.Text := 'Active';
    Inactive: Edit1.Text := 'Inactive';
  end;
end;

or

const
  StatusStr: array[Status] of String = ('Active', 'Inactive');
begin
  Edit1.Text := StatusStr[StatusOfStudent];
end;

or (using RTTI):

uses
  TypInfo;
begin
  Edit1.Text := GetEnumName(TypeInfo(Status), Integer(StatusOfStudent));
end;

"Linden Willms" <lwil...@telusplanet.net> schreef in bericht
news:39C04DFA.40B24BA@telusplanet.net...

Quote
> I have the following as part of my data structure:

> type
>   Status:(Active,InActive);

>   StudentRecord = packed record
>                    StatusOfStudent: Status;
>   end;

> Now how do I  display a Status in TEdit ?

> Thanks,
> Linden

Re:TEdit..Display user defined Types


Thanks a lot folks

Linden

Other Threads