Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2003, 10:20 AM
MMDelbari MMDelbari is offline
Member
 
Join Date: Jun 2003
Posts: 97
Default using case statement for a const WideString

Hi,
I have used a voice recognition component and one of its events have a const Phrase: WideString
in its declration.
i want to use :
case Phrase of
'hello':
'bye' :
end;

to decide what to do with the phrase extracted from the voice but the problem is Delphi raises
an exception in the case block and says that Phrase(as it declraded as a WideString in event)
is not Ordinal type.
Then how can i use the case(or sth like that) for the Phrase: WideString to decide what to do?

Any help is Admired...


Help!
MMD
Reply With Quote
  #2  
Old 06-24-2003, 10:32 AM
simes simes is offline
Senior Member
 
Join Date: Jan 2002
Posts: 2,327
Default RE: using case statement for a const WideString

Have a function the takes a widestring and returns an ordinal type, such as an enumerated type. Code the case statement to use this enumerated type.

TPhrase = (phHello, phBye...);

function StrToPhrase(const str: string): TPhrase;
//test your phrases and return an TPhrase.


case StrToPhrase(phrase) of
phHello: //...
phBye: //...
end;

Please click accept if this helps

Simon
SadMan Software
http://www.simes.clara.co.uk
(No emails please unless explicitly requested!)
Reply With Quote
  #3  
Old 06-24-2003, 10:03 PM
PetrB PetrB is offline
Senior Member
 
Join Date: Jul 2002
Posts: 530
Default RE: using case statement for a const WideString

Hi,
try this way:

Function IndexFromArray(Const VWhat : String;Const Vst : Array Of String) : LongInt;
Begin
Result:=High(Vst);
While (Result>=Low(Vst)) And (Vst[Result]<>VWhat) Do
Dec(Result);
End;

...
Case IndexFromArray(MyText,['say','hello',....] Of
0 : Say reaction
1 : hello reaction
....
End;

You can use WideString instead of String, put better compare mechanism to IndexFromArray (e.g. case insensitive).

If it help you please give me a point.
PB
Reply With Quote
Reply

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 On

Forum Jump


All times are GMT. The time now is 12:48 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.