How can i replace a pointer in runtime?

M

Me

Hey,

First, what i have is a form and a few panels. my code:

if(Partytent->Panel5x5a->Left+Partytent->Panel5x5a->Width >=
Partytent->Panel5x5b->Left-2 && Partytent->Panel5x5a->Top >=
Partytent->Panel5x5b->Top-5 && Partytent->Panel5x5a
->Top+Partytent->Panel5x5a->Height <=
Partytent->Panel5x5b->Top+Partytent->Panel5x5b
->Height+5 && Partytent->Panel5x5a->Left+Partytent->Panel5x5a->Width <=
Partytent
->Panel5x5b->Left+1){
left=1;
}
else
left=0;

Allright, this is a little difficult, so in steps:

The first pointer in the if-statement is:

Partytent->Panel5x5a->Left

What i want is a function where i can give "5x5" with, "a", so
something like this:

void __fastcall TPartytent::checkAfstandTenten(TObject *Sender, String
TypeEerste, String TypeTweede) {

String tmp;
tmp="Partytent->Panel" + TypeEerste + een + "->Left";

and then in the if-statement: if(tmp==100){} for example.

So anyone think this is possible? Or how to do this anyway? The pointer
still has to point to the panel.

I want to change the pointer by call of this function.
 
A

Alf P. Steinbach

* Me:

Hey hey.

First, what i have is a form and a few panels.

That's outside the scope if this newsgroup: here it's all & only about C++.

my code:

if(Partytent->Panel5x5a->Left+Partytent->Panel5x5a->Width >=
Partytent->Panel5x5b->Left-2 && Partytent->Panel5x5a->Top >=
Partytent->Panel5x5b->Top-5 && Partytent->Panel5x5a
->Top+Partytent->Panel5x5a->Height <=
Partytent->Panel5x5b->Top+Partytent->Panel5x5b
->Height+5 && Partytent->Panel5x5a->Left+Partytent->Panel5x5a->Width <=
Partytent
->Panel5x5b->Left+1){
left=1;
}
else
left=0;

Allright, this is a little difficult, so in steps:

The first pointer in the if-statement is:

Partytent->Panel5x5a->Left

The answer to complexity is abstraction, in essence, /name/ those
sumbitches that appears in your code, like

Panel const& a = *Partytent->Panel5x5a;
Panel const& b = *Partytent->Panel5x5b;

bool const isLeft =
a.Left + a.Width >= b.Left - 2 &&
a.Top >= b.Top - 5 &&
a.Top + a.Height <= b.Top + b.Height + 5 &&
a.Left + a.Width <= b.Left + 1;

What i want is a function where i can give "5x5" with, "a", so
something like this:

void __fastcall TPartytent::checkAfstandTenten(TObject *Sender, String
TypeEerste, String TypeTweede) {

String tmp;
tmp="Partytent->Panel" + TypeEerste + een + "->Left";

No, you can't (in general) generate code on the fly in C++. What you
can do is use abstraction, /name/ those things. E.g. define a type
PanelPair, where one instance is named 5x5, containing panels a and b.

and then in the if-statement: if(tmp==100){} for example.

Huh.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top