Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delphi's with..do block in C?

Status
Not open for further replies.

BobbaFet

Programmer
Feb 25, 2001
903
NL
Is there an equivalent for Delphi's with..do block in C?

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
I suspect the while ... do or do ... while loops may work. It's been a long time since I've programmed in Pascal.

James P. Cottingham
I'm number 1,229!
I'm number 1,229!
 
with with do blocks you can do stuff like:
Code:
[b]with[/b] ObjectX [b]do[/b]
  [b]begin[/b]
  property1 := this;
  property2 := that;
  property3 := False;
  [b]end;[/b]

Basically, it allows you to access the same object without having to redeclare the object over and over again.


[bobafett]  [u][i]Bobba[b]Fet[/b][/i][/u]  [bobafett]
[code]
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
In C++ it's more like:
Code:
ObjectX->property1 = this;
ObjectX->property2 = that;
ObjectX->property3 = False;

No with...do.


James P. Cottingham
I'm number 1,229!
I'm number 1,229!
 
Yes, in Delphi you would normally use:

Code:
ObjectX.Property1 := this;
ObjectX.Property1 := that;
ObjectX.Property1 := False;

But when you need to set a lot of properties and/or use a lot of methods you can use with..do blocks to shorten it. But from what I understand there is no such thing in Cpp?

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
AFAIK, no, there is not anything like that in C++, at least in the Builder versions I've used.



James P. Cottingham
I'm number 1,229!
I'm number 1,229!
 
If the name of your object is long:
place

#define MyVery_very_and_very_long_object_name Short

Short->property1 = this;
Short->property2 = that;
 
An look alike could be:

#define M(T) Memo_c->Lines->Append(T)

M("Some ...");
...
M("Some....");

#undef M

 
Ok, ty all for your imput! Too bad there isn't, it really helps with code readability, the shortening of names is a good alternative and I will use that instead.

[bobafett] BobbaFet [bobafett]
Code:
if not Programming = 'Severe Migraine' then
                       ShowMessage('Eureka!');
 
No needs in with-like construct in C++. You can access class/structure members directly in member functions. To access public data members outside their class is a bad (at least ancient) programming style (so Pascal with construct is simply yet another rudiment of old good "structured programming" ;)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top