Im having a bit of trouble converting the delphi code below into c++, i'm sure I need to use a Switch statement but I seem to be getting it wrong. Basically, I have 6 panels mounted on a larger Panel, each caption will contain a random number.
A button then decides the caption of the next panel and compares it to the previous and decides whether it is higher, lower or a pair. Each of those three are pre-defined enumerated types.
I'm just having trouble getting a working version with c++ builder, can anyone help?

case pnlCards.Tag of
0 :
result := prediction;
1..5 :
with pnlCards.Controls[pnlCards.Tag] as TPanel do
if Tag > pnlCards.Controls[pnlCards.Tag-1].Tag then
result := higher;
if Tag < pnlCards.Controls[pnlCards.Tag-1].Tag then
result := lower;
if Tag = pnlCards.Controls[pnlCards.Tag-1].Tag then
result := pair;

Recommended Answers

All 4 Replies

Eh, why not?


switch (pnlCards.Tag) {
  case 0:
    result = prediction;
  case 1: case 2: case 3: case 4: case 5:
    TPanel p  = (TPanel)(pnlCards.Controls[ pnlCards.Tag ]);
    TPanel p0 = (TPanel)(pnlCards.Controls[ pnlCards.Tag-1 ]);
    if (p.Tag > p0.Tag)
      result = higher;
    if (p.Tag < p0.Tag)
      result := lower;
    if (p.Tag == p0.Tag)
      result := pair;


I took a single liberty to make typing easier. This code could be much better written in both Pascal and in C++.

Thankyou for the quick reply.

I must apologise, the entire program is actually a template, where its much easier just to carry on than start from scratch.
That is exactly what I have but it is not giving me the answers.
For example, I decided to output the result into a label's caption property with a bit of extra code, it would continuously say the result was lower

Ah, I reworked my code based on yours and it now works, baffling but embarassing! Thanks for your help.

AdvSmoothPageSlider1.ActivePageIndex := 0;
(Sender as TAdvSmoothButton).visible := False;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.