[DUG] Why use a set when a string will work OK (and less code)?

Nick nick at salehoo.com
Thu May 10 10:48:38 NZST 2007


Why use a set when string work ok? (and I think it's a set)
Question: I have seen this quite a bit and apparently it's "good 
practice" however to me it seems like more work.
Example

Whats the point in doing this
MyStatus = (Active, Pending, Ended, Paused, Deleted, Suspended););
type
  Something = class
  name : string;
  status : MyStatus;
end;

then example on create or something
  status := Active;

(yes, missed out lots of steps :P)
and now if I want to show the status, I have to do something like..
If status = MyStatus(Active) then showmessage('Active');
If status = MyStatus(Pending) then showmessage('Pending');  etc

Why go though all that hassle when just doing this is fine
 status : string;
 status := 'Active'
 showmessage(status);

so instead of using "MyStatus" types I just use a string - this means 
when I want to output the status to the user I don't have to try and 
convert it to string first.
So, why do it?

Hmmmm
Nick


More information about the Delphi mailing list