Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 02-11-2006, 03:39 AM
Stephenkinloch Stephenkinloch is offline
Member
 
Join Date: Sep 2005
Posts: 87
Default TParity Question

Hi,

The problem is to do with compatability.

See the following code:

ApdComport.Baud:=StrToInt(RadioGroup1.Items[RadioGroup1.ItemIndex]);

from this code you can see that "Baud" is an integer and requires the "RadioGroup.Items....." part to be converted to a compatable type i.e. using the StrToInt command.

I understand this and the above line of code works. However, when trying the following code a compatability error occurs:

ApdComport.Parity:=StrToInt(RadioGroup2.Items[RadioGroup2.ItemIndex]);

the error says that TParity is not compatable with String. I have tried various different types but have not been successfull.

Does anyone know what can fill the "StrToInt" part?

Thanks,

Stephen.
Reply With Quote
  #2  
Old 02-11-2006, 03:42 AM
krjt krjt is offline
Senior Member
 
Join Date: Oct 2005
Posts: 203
Default RE: TParity Question

TParity is integer?

I hope this helps you, if yes please accept as answer I always accept the helping answer.

cheers,
krjt
Reply With Quote
  #3  
Old 02-11-2006, 03:46 AM
gLes gLes is offline
Senior Member
 
Join Date: Jan 2001
Posts: 2,273
Default RE: TParity Question

As I see this TParity type is an enum type, which means it is compatible with an Integer, so you can do this:

[delphi]ApdComport.Parity := RadioGroup2.ItemIndex;[/delphi]

Just make sure the items in the radiogroup are in the same order as the appropriate enum constants of the TParity type

gLes
Reply With Quote
  #4  
Old 02-11-2006, 03:47 AM
krjt krjt is offline
Senior Member
 
Join Date: Oct 2005
Posts: 203
Default RE: TParity Question

Tparity is not an integer.

The solution is

[DELPHI]Case RadioGroup2.ItemIndex of
0 : ApdComport.Parity:=pNone;
1 : ApdComport.Parity:=pOdd;
2 : ApdComport.Parity:=pEven;
3 : ApdComport.Parity:=pMark;
4 : ApdComport.Parity:=pSpace;
end;[/DELPHI]



I hope this helps you, if yes please accept as answer I always accept the helping answer.

cheers,
krjt
Reply With Quote
  #5  
Old 02-11-2006, 04:04 AM
Stephenkinloch Stephenkinloch is offline
Member
 
Join Date: Sep 2005
Posts: 87
Default RE: TParity Question

Cheers guy's,

Krjt, how do i incorporate that code into the following?


TForm2.RadioGroup2Click(Sender: TObject);
Begin

ApdComport.Parity:=StrToInt(RadioGroup2.Items[RadioGroup2.ItemIndex]);

end;
Reply With Quote
  #6  
Old 02-11-2006, 04:08 AM
krjt krjt is offline
Senior Member
 
Join Date: Oct 2005
Posts: 203
Default RE: TParity Question

[DELPHI]TForm2.RadioGroup2Click(Sender: TObject);
begin
Case RadioGroup2.ItemIndex of
0 : ApdComport.Parity:=pNone;
1 : ApdComport.Parity:=pOdd;
2 : ApdComport.Parity:=pEven;
3 : ApdComport.Parity:=pMark;
4 : ApdComport.Parity:=pSpace;
end;
end;[/DELPHI]

{I assume the items in RadioGroup2 are in the following order: pNone, pOdd, pEven, pMark, pSpace}

I hope this helps you, if yes please accept as answer I always accept the helping answer.

cheers,
krjt
Reply With Quote
  #7  
Old 02-11-2006, 04:33 AM
krjt krjt is offline
Senior Member
 
Join Date: Oct 2005
Posts: 203
Default RE: TParity Question

For all the four parameters (Baud, Parity, DataBits, StopBits) I hope you have four radiogroups.

For radiogroup1 the items are : 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, and 115200.

For radiogroup2 the items are: None, Odd, Even, Mark, Space.

For radiogroup3 the items are: 5, 6, 7, 8

For radiogroup4 the items are: 1, 2

Then the onclick events should be as below:

[DELPHI]procedure TForm1.RadioGroup1Click(Sender: TObject);

const
bRate : Array [0..8] of integer = (300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200);

begin
TApdComPort.Baud:=bRate[RadioGroup1.ItemIndex];
end;

procedure TForm1.RadioGroup2Click(Sender: TObject);
begin
Case RadioGroup2.ItemIndex of
0 : TApdComPort.Parity:=pNone;
1 : TApdComPort.Parity:=pOdd;
2 : TApdComPort.Parity:=pEven;
3 : TApdComPort.Parity:=pMark;
4 : TApdComPort.Parity:=pSpace;
end;
end;

procedure TForm1.RadioGroup3Click(Sender: TObject);
begin
TApdComPort.DataBits:=5+RadioGroup3.ItemIndex;
end;

procedure TForm1.RadioGroup4Click(Sender: TObject);
begin
TApdComPort.StopBits:=1+RadioGroup4.ItemIndex;
end;[/DELPHI]

I hope this helps you, if yes please accept as answer I always accept the helping answer.

cheers,
krjt
Reply With Quote
  #8  
Old 02-11-2006, 04:39 AM
Stephenkinloch Stephenkinloch is offline
Member
 
Join Date: Sep 2005
Posts: 87
Default RE: TParity Question

Cheers,

Yeah i have all of those radiogroups. I also have another one for handshaking details i.e. None, Xon/Xoff, RTS/CTS, DTR/DSR.

Cheers for your help.

Code was perfect.

Stephen.
Reply With Quote
  #9  
Old 02-11-2006, 04:48 AM
krjt krjt is offline
Senior Member
 
Join Date: Oct 2005
Posts: 203
Default RE: TParity Question

Good luck with your project.

I hope this helps you, if yes please accept as answer I always accept the helping answer.

cheers,
krjt
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 11:50 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2017, vBulletin Solutions, Inc.