Delphi XE TBytes default parameters.

Bought Delphi XE. Tried to compile my programs:

Error: Parameters of this type cannot have default values:

Turns out that TBytes no longer can have default parameter!

---

Research gives the following... Declare

  TArray1 = array of Byte;
  TArray2 = TArray<Byte>;

then 

  procedure ByFunc1(AArray: TArray1 = nil)

works fine, but

  procedure ByFunc1(AArray: TArray2 = nil)

gives compiler error: Parameters of this type cannot have default values:

--

That TBytes cannot have default parameters is really a breaking change.

I have known that generics have not been "fully implemented" and have been careful of where I use them. Now I'm suddenly forced into them by the new declaration of TBytes. 

What should I do? I really need default parameters. I could go through my application and replace all TBytes with TByteDynArray...
-1
Sungam
9/10/2010 9:59:09 AM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

7 Replies
1420 Views

Similar Articles

[PageSpeed] 50

Magnus Wangefors wrote:

> Bought Delphi XE. Tried to compile my programs:
> 
> Error: Parameters of this type cannot have default values:
> 
> Turns out that TBytes no longer can have default parameter!
> 
> ---
> 
> Research gives the following... Declare
> 
>   TArray1 = array of Byte;
>   TArray2 = TArray<Byte>;
> 
> then 
> 
>   procedure ByFunc1(AArray: TArray1 = nil)
> 
> works fine, but
> 
>   procedure ByFunc1(AArray: TArray2 = nil)
> 
> gives compiler error: Parameters of this type cannot have default
> values:

QC it. 

As a workaround remove the default value, build the application, and on
every call where the compiler moans about a missing parameter, pass a
Nil...

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
-1
Peter
9/10/2010 11:06:29 AM
> As a workaround remove the default value, build the application, and
> on every call where the compiler moans about a missing parameter,
> pass a Nil...

Or add an overload that passes nil to the original method.
-1
Chris
9/10/2010 5:18:18 PM
Chris Rolliston wrote:

> > As a workaround remove the default value, build the application, and
> > on every call where the compiler moans about a missing parameter,
> > pass a Nil...
> 
> Or add an overload that passes nil to the original method.

Yes, that is a better solution.

-- 
Peter Below (TeamB)  
Don't be a vampire (http://slash7.com/pages/vampires), 
use the newsgroup archives :
http://codenewsfast.com
http://groups.google.com
1
Peter
9/11/2010 8:06:51 AM
:-), Well...

I simplified my example, overloading works in some places like my example, but a bunch of my functions are more like

function FFoo(P1: TX1; P2: TX2; P3: TX3 = nil; ABytes: TBytes = nil; AString: String = nil; ...) 

and they are called in 100'eds of places, so...

I have QC'ed it...

But, yes, if we are to adopt Delphi XE, I will have to solve it with overloads, and compiler detections and many hours of work...

/W
1
Sungam
9/13/2010 10:20:31 AM
> I simplified my example, overloading works in some places like my
> example, 

Er, so you've saying that XE *doesn't* actually have a problem with
default paramters for dynamic arrays, as you originally claimed?

> but a bunch of my functions are more like
> 
> function FFoo(P1: TX1; P2: TX2; P3: TX3 = nil; ABytes: TBytes = nil;
> AString: String = nil; ...)

Another dodgy example, given the last parameter.
-1
Chris
9/13/2010 8:12:37 PM
> {quote:title=Chris Rolliston wrote:}{quote}
> > I simplified my example, overloading works in some places like my
> > example, 
> 
> Er, so you've saying that XE *doesn't* actually have a problem with
> default paramters for dynamic arrays, as you originally claimed?
> 

Er, no. I am just acknowledging that using overloading can in some cases remove the need for default parameters.

And, sorry, i was a bit unclear in my first post. The problem is not with dynamic arrays, not in XE, never has been. The problem is with generics, and TBytes is in XE defined by a generic 

TBytes = TArray<Byte>.

and no longer

TBytes = array of Byte.

and this has consequences...


> > but a bunch of my functions are more like
> > 
> > function FFoo(P1: TX1; P2: TX2; P3: TX3 = nil; ABytes: TBytes = nil;
> > AString: String = nil; ...)
> 
> Another dodgy example, given the last parameter.

The last default parameter value is obviously a typo.

What I am trying to say is that the trick with using overloading to remove the need for default parameters only work if the parameter in question is the last parameter. (Unless you want to create an overload for every default parameter).



/W
1
Sungam
9/15/2010 6:31:04 AM
> And, sorry, i was a bit unclear in my first post. The problem is not
> with dynamic arrays, not in XE, never has been. The problem is with
> generics, and TBytes is in XE defined by a generic
> 
> TBytes = TArray<Byte>.
> 
> and no longer
> 
> TBytes = array of Byte.

Sorry, that makes sense now. 

> > > but a bunch of my functions are more like
> > > 
> > > function FFoo(P1: TX1; P2: TX2; P3: TX3 = nil; ABytes: TBytes =
> > > nil; AString: String = nil; ...)
> > 
> > Another dodgy example, given the last parameter.
> 
> The last default parameter value is obviously a typo.

It's difficult to tell with made up code, especially with something
like that (a string variable can be 'nil' internally, the compiler just
artificially requires a cast to Pointer to find out whether this is the
case)...
-1
Chris
9/15/2010 10:53:06 AM
Reply:

Similar Artilces:

Delphi XE / Delphi 2010
Hello! I noticed that Embarcadero® Delphi® 2010 Version is not on the list of products on Embarcadero page. Or is it still possible to buy it? Will RAD Studio XE compile programs written in Delphi 2010 without problems.? Thanks. Am 13.09.2010 09:04, schrieb Petra Nemec: > Will RAD Studio XE compile programs written in Delphi 2010 without problems.? As always you will probably have to recreate the projects as the import is still a bit -- special. Christian Hello! Does anybody know if it is still possible to get a Delphi2010 trial version (if yes where)? ...

Delphi 7 to Delphi XE
Have been using Delphi 7 for many moons ( have got later versions but never upgraded to ) My first problem is: Component Palette. in XE it is a small toolbar docked in top right in Delphi 7 it gives a large view of all the components. I am struggling to be able to cope/access my components.in Delphi XE. Can I make the component pallette tool bar the same size as Delphi 7, or is there a fast way to view/choose all available components in XE, that I have not spotted yet? Kind Regards, Robert. Hi, What I know is that in Delphi 2010 and XE you can choose between t...

Error on Delphi 6 but not on Delphi Xe for Ftp
I am Experimenting with get a file from our webside server via Ftp. I have 2 Machines 1 a laptop runing XP Delphi 6 Indy 10.5.8.0 An a machine runing Window 7 Delphi XE2 with Indy 10.5.8.0. I am using the Same Code on Both. procedure TFrmMain.ProcessItemDalySpecial; var PathDest : String; FileName : String; begin with FrmTb2 do begin if ReadIniBoolean(IniCfg,'FTP','UseFtpDaly') then begin Ftp.Host := ReadIniStr(IniCfg,'FTP','HostDaly'); Ftp.Port := ReadIniInt(IniCfg,'FTP'...

Migrating to Delphi XE from Delphi 7.0
Below is my code in Delphi 7.0, this is how to call another units in webmodule... Hello All, I create a web application in Delphi 7.0, using the Web Server Application, CGI, IntraWeb 7.0.15. And I used TIWPageProducer to view like this url "http://localhost/mcr/mcr.exe/main". I built and run. I viewed in thru IIS and it is running... This is my code in Delphi 7.0 .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1....

Migrating to Delphi XE from Delphi 7.0
Below is my code in Delphi 7.0, this is how to call another units in webmodule... Hello All, I create a web application in Delphi 7.0, using the Web Server Application, CGI, IntraWeb 7.0.15. And I used TIWPageProducer to view like this url "http://localhost/mcr/mcr.exe/main". I built and run. I viewed in thru IIS and it is running... This is my code in Delphi 7.0 .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end;...

Migrate from Delphi 2007 for Win32 to Delphi XE
we use Delphi 2007 for Win32 to support legacy (32Bit) OWL-based pascal applications (yes i know it was a mistake not to switch to VCL 15 years ago). could our applications still be opened and compiled with Delphi XE? The existing projects are all plain Pascal-Code, coming back from the times of Turbo Pascal for Windows and later on Borland Pascal. Are there any improvements we could profit from (i.e IDE, Debugger)? Thanks Andrej > {quote:title=Andrej Dimic wrote:}{quote} > could our applications still be opened and compiled with Delphi XE? I'm not sure, but I guess ...

Delphi 7.0 code convert to delphi XE ...
Hello All, I create an application using Web Server Application then CGI stand alone... In WebModule I add ModuleController component and IWPageProcedure... Below is my code in Delphi 7.0, this is how to call another units in webmodule... .... .... procedure TWebModule1.proMainGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmMain.Create(AWebApplication); end; procedure TWebModule1.proLogInGetForm(ASender: TIWPageProducer; AWebApplication: TIWApplication; var VForm: TIWPageForm); begin VForm := TfrmLogIn.Create(AWebA...

Any difference between Delphi Prism 2011 and Delphi Prism XE?
Looking at the features in Delphi Prism XE, they look the same as the new items in the 2011 release back in may. I there anything new in the XE release? or did they simply change the product branding? Just wondering if I need to update it or now when i download the rest. Thanks, Hi Dan, > Looking at the features in Delphi Prism XE, they look the same as the new items in the 2011 release back in may. I there anything new in the XE release? or did they simply change the product branding? Just wondering if I need to update it or now when i download the rest. See http://w...

Migrating from Delphi 6 to Delphi XE 3! [Edit]
All, I am a Delphi developer working in an windows form application developed using Delphi 6. Now, we are planning to upgrade the development tool. Can anyone provide me information related to major roadblocks that we can face while migrating from Delphi 6 to Delphi XE 3? Should we migrate to Delphi XE 3 or any other preferred version of Delphi based on the fact that our target users will be using Windows 7 or Windows 8? Do we have any tools or utilities to migrate the source code from Delphi 6 to higher version of Delphi? Also, any suggestions related to best practices are welcome....

Delphi 5 (string[80]) vs Delphi XE
Hi guys i'm trying to convert a old application made with Delphi 5 to Delphi XE 5 The probleme i have right now is about String[80] and the Read / Write procedure i have a type like that Type TEnrMess = record Mess : String[80]; MessSuiv : Word; Hint : Word; end; And i read/write this type to a File of TEnrMess My probleme is that the string have changed from Delphi 5 to Delphi XE i join the link of a simple of the probleme that can be compiled on delphi 5 and any Delphi XE https://mega.co.nz/#!wV1VyZzY!1ha5oOxTg7L1WJAOXutUygkj...

Migration from Delphi 2007 Rad to Delphi XE Where is Quickreports
Have installed and finally registered Delphi Xe, I am looking for Quickreports but am unable to find it anywhere, I asked the Distributer and was told its packaged in Delphi XE, Well I should have gone to specsavers......cos I cant see it any where ? > {quote:title=Colin Coleman wrote:}{quote} > Have installed and finally registered Delphi Xe, I am looking for Quickreports but am unable to find it anywhere, I asked the Distributer and was told its packaged in Delphi XE, Well I should have gone to specsavers......cos I cant see it any where ? Hello Colin, Delphi X...

Delphi 7 to Delphi XE: TBlobField to XML [Edit]
Hi, I'm migrating a Delphi7 application to Delphi XE. I'm using a TClientDataSet to communicate, by using a XML frame, with my server. In this TClientDataSet I'm using a TBlobField which is an array of 384 byte. The blobField is allocate by a code like this : {code} myStream : TStream; myStream := aClientDataSet.CreateBlobStream(myBlobField, bmwrite); vResult := myStream.Write(ArrayOf384Byte[0], length(ArrayOf384Byte)); //vResult = 384 => GooD ! (...) {code} For communicate with the server, we have to decode the Blobfield in XML before to sending it. We have...

Delphi and Delphi for .Net
It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. I would like to know is it true all .Net application is slower than Win32 native applicaiton or it is Delphi for .Net only. Your information is great appreciated, Inung On 2011-06-21 18:20:17 +0100, Inung Huang said: > It seems that Delphi for .Net is slower than Delphi Win32 native applicaiton. > I would like to know is it true all .Net application is slower than > Win32 native applicaiton or it is Delphi for .Net only. If you are only running the code in the application once then, yes, yo...

ShowMessage/MessagDlg wordwrap Delphi 2006
Hi, I have used Delphi 2006 up to now. ShowMessage allowed a long text without a word wrapping. Now with Delphi XE I notice that a migrated program shows smaller message window sizes and a previously carefully aligned message now appears wrapped and misaligned. How to get back to the previous behaviour? I'm not experienced to create my custom form, so a code snippet may help. Thanks, Uli Edited by: Ulrich Brueggemann on Sep 18, 2010 8:46 AM > I have used Delphi 2006 up to now. > ShowMessage allowed a long text without a word wrapping. > > Now with Delphi ...

Web resources about - Delphi XE TBytes default parameters. - embarcadero.delphi.general

Parameter - Wikipedia, the free encyclopedia
A parameter (from the Ancient Greek παρά , "para", meaning "beside, subsidiary" and μέτρον , "metron", meaning "measure"), in its common meaning, ...

fb_source Parameter - Facebook-Entwickler
This document lists the complete list of values for the fb_source parameter that is returned with th...

Google Webmaster Tools Parameter Handling - Flickr - Photo Sharing!
You aren't signed in Sign In Help Home The Tour Sign Up Explore Explore Home Last 7 Days Interesting Popular Tags Calendar Most Recent Uploads ...

Cat 8: TIA performance standards committee chairman previews parameters of forthcoming twisted-pair cable ...
Category 8, the next-generation twisted-pair cabling specification, is still in development, but the outlook looks quite positive that it will ...

Philippine president asks for 'parameters' of Mayon Volcano tours
Philippine president asks for 'parameters' of Mayon Volcano tours People's Daily Online ... 26, 27, 28, 29, 30, 31. Jan, Feb, Mar, Apr, May, ...

Alternatives to boolean parameters
... ) { PrintLine ( item . Name ); if ( printDetails ) { PrintLine ( item . Description ); } } } Aha! Now can see that the boolean parameter ...

Exporting Error (Error in Parameter...: Apple Support Communities
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability ...

Apple tech monitors device aging, adjusts operating parameters to ensure optimal performance
... describing a method of monitoring the aging of a device's electronics, comparing the data with a global average and modifying operating parameters ...

Is it poor programming practice to pass parameters as objects?
... a free, community-powered network of 100+ Q&A sites . Risser asked: So, we've got a guy who likes to write methods that take Objects as parameters, ...

Parameter Short Film Competition sponsored by Grolsch
Grolsch presents Parameter The A.V. Club Short Film Competition Please Enter Your Date of Birth Ineligible entry Enter For people over the age ...

Resources last updated: 12/8/2015 3:14:50 AM