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!1ha5oOxTg7L1WJAOXutUygkjq42aTeaQT58lVYfmXI0

This sample exacly show the probleme, Note that i need to read the the file correcly in the new version of Delphi

Thanks for any help

Christian
0
Christ
10/10/2014 2:43:28 PM
embarcadero.delphi.general 4258 articles. 0 followers. Follow

14 Replies
1252 Views

Similar Articles

[PageSpeed] 57

Jeff Overcash (TeamB) wrote:

> Christ Fill wrote:
> > {code} 
> > Type TEnrMess = packed record
> >        Mess       : String[80];
> >        MessSuiv   : Word;
> >        Hint       : Word;
> >    end;
> > {code}
> > 
> > Work in Delphi XE but not in Delphi 5 give EinOutError Read beyond end of file
> > The trick is that the file are allready generated in delphi 5 (saved) and i need to read it in
> > Delphi XE
> > 
> > i thinki will need to make a converter in Delphi 5 using your packed record ...
> 
> Both the writer and reader should agree on alignment of the record.  Because 
> your string[80] is actually 81 bytes long the next item is going to have padding 
> in before it it written if not packed.  I think you will find that the 
> sizeof(TEnrMsg) is different between D5 and XE5.  The difference is the byte 
> padding.  Using packed tells it not to align the record.  I think in D5 it was 
> word aligned (2 bytes), later it was changed to default to quadword (8 bytes).
> 
> You can try in your XE code to change the alignment for that record to word like
> 
> {$A2}
>    TEnrMess = record
>       name : string[80];
>       age  : Integer;
>       male : Boolean;
>    end;
> {$A8}
> 
> The above gives the following record sizes ( sizeof(TEnrMess) )
> 
> {$A8} 92 (default for XE)
> {$A4} 92
> {$A2} 88 (I think this was D5's default but do not recall)
> {$A1} 86 (equivalent to alignment off)
> 
> 
> Optimally though you should always pack your records if writing them to a file 
> so that changes in record alignment does not have the negative impacts you are 
> seeing.

Jeff,
Note that Christian has shown two different structures, I don't know which is correct.
(just noticed...)

-- 
Tom Brunberg
firstname.lastname@welho.com
0
Tom
10/10/2014 1:01:01 AM
Christ Fill wrote:

> 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

Hi Christian,
Shortstring (and variations like string[80]) are still the same in XE5.
Please explain what the problem is, I and many others don't like to download files from the net, in
order to learn the problem.

It might be that the problem is related to memory alignment, inwhich case {$A1} might help.


-- 
Tom Brunberg
firstname.lastname@welho.com
0
Tom
10/10/2014 3:25:15 PM
Perfect, here a sample code...
The error come from TCustomer  that use the name string[80],  thos code worke perfecly in Delphi 5 and Delphi XE, but its look like the data saved it's not the same  on each version
Like a said is your wanna see more specifily the trouble check my link (it's only source, and bin compiled from Delphi 5 and Delphi XE 5)


type
   TCustomer = Record
     name : string[80];
     age  : Integer;
     male : Boolean;
   end;
 
 var
   myFile   : File of TCustomer;  // A file of customer records
   customer : TCustomer;          // A customer record variable
 
 begin
   // Try to open the Test.cus binary file for writing to
   AssignFile(myFile, 'Test.cus');
   ReWrite(myFile);
 
   // Write a couple of customer records to the file
   customer.name := 'Fred Bloggs';
   customer.age  := 21;
   customer.male := true;
   Write(myFile, customer);
 
   customer.name := 'Jane Turner';
   customer.age  := 45;
   customer.male := false;
   Write(myFile, customer);
 
   // Close the file
   CloseFile(myFile);
 
   // Reopen the file in read only mode
   FileMode := fmOpenRead;
   Reset(myFile);
 
   // Display the file contents
   while not Eof(myFile) do
   begin
     Read(myFile, customer);
     if customer.male
     then ShowMessage('Man with name '+customer.name+
                      ' is '+IntToStr(customer.age))
     else ShowMessage('Lady with name '+customer.name+
                      ' is '+IntToStr(customer.age));
   end;
 
   // Close the file for the last time
   CloseFile(myFile);
 end;
0
Christ
10/10/2014 3:38:38 PM
Perfect, here a sample code...
The error come from TCustomer  that use the name string[80],  thos code worke perfecly in Delphi 5 and Delphi XE, but its look like the data saved it's not the same  on each version
Like a said is your wanna see more specifily the trouble check my link (it's only source, and bin compiled from Delphi 5 and Delphi XE 5)
https://mega.co.nz/#!wV1VyZzY!1ha5oOxTg7L1WJAOXutUygkjq42aTeaQT58lVYfmXI0


type
   TCustomer = Record
     name : string[80];
     age  : Integer;
     male : Boolean;
   end;
 
 var
   myFile   : File of TCustomer;  // A file of customer records
   customer : TCustomer;          // A customer record variable
 
 begin
   // Try to open the Test.cus binary file for writing to
   AssignFile(myFile, 'Test.cus');
   ReWrite(myFile);
 
   // Write a couple of customer records to the file
   customer.name := 'Fred Bloggs';
   customer.age  := 21;
   customer.male := true;
   Write(myFile, customer);
 
   customer.name := 'Jane Turner';
   customer.age  := 45;
   customer.male := false;
   Write(myFile, customer);
 
   // Close the file
   CloseFile(myFile);
 
   // Reopen the file in read only mode
   FileMode := fmOpenRead;
   Reset(myFile);
 
   // Display the file contents
   while not Eof(myFile) do
   begin
     Read(myFile, customer);
     if customer.male
     then ShowMessage('Man with name '+customer.name+
                      ' is '+IntToStr(customer.age))
     else ShowMessage('Lady with name '+customer.name+
                      ' is '+IntToStr(customer.age));
   end;
 
   // Close the file for the last time
   CloseFile(myFile);
 end;

Edited by: Christ Fill on Oct 10, 2014 8:40 AM
0
Christ
10/10/2014 3:40:16 PM
Christ Fill wrote:
> 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!1ha5oOxTg7L1WJAOXutUygkjq42aTeaQT58lVYfmXI0
> 
> This sample exacly show the probleme, Note that i need to read the the file correcly in the new version of Delphi
> 
> Thanks for any help
> 
> Christian

Short string has not changed between D5 and XE5.  I do think that the default 
byte alignment has.  You should always used packed on records that are going to 
be streamed in and out of files so default alignment of the compiler doesn't 
matter between versions.

try this and see if it helps.

{code}
  Type TEnrMess = packed record
       Mess       : String[80];
       MessSuiv   : Word;
       Hint       : Word;
   end;
{code}

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
0
Jeff
10/10/2014 3:41:28 PM
Christ Fill wrote:

> Perfect, here a sample code...
> The error come from TCustomer  that use the name string[80],  thos code worke perfecly in Delphi
> 5 and Delphi XE, but its look like the data saved it's not the same  on each version Like a said
> is your wanna see more specifily the trouble check my link (it's only source, and bin compiled
> from Delphi 5 and Delphi XE 5)
> https://mega.co.nz/#!wV1VyZzY!1ha5oOxTg7L1WJAOXutUygkjq42aTeaQT58lVYfmXI0
> 
> 
> type
>    TCustomer = Record
>      name : string[80];
>      age  : Integer;
>      male : Boolean;
>    end;
>  
>  var
>    myFile   : File of TCustomer;  // A file of customer records
>    customer : TCustomer;          // A customer record variable
>  
>  begin
>    // Try to open the Test.cus binary file for writing to
>    AssignFile(myFile, 'Test.cus');
>    ReWrite(myFile);
>  
>    // Write a couple of customer records to the file
>    customer.name := 'Fred Bloggs';
>    customer.age  := 21;
>    customer.male := true;
>    Write(myFile, customer);
>  
>    customer.name := 'Jane Turner';
>    customer.age  := 45;
>    customer.male := false;
>    Write(myFile, customer);
>  
>    // Close the file
>    CloseFile(myFile);
>  
>    // Reopen the file in read only mode
>    FileMode := fmOpenRead;
>    Reset(myFile);
>  
>    // Display the file contents
>    while not Eof(myFile) do
>    begin
>      Read(myFile, customer);
>      if customer.male
>      then ShowMessage('Man with name '+customer.name+
>                       ' is '+IntToStr(customer.age))
>      else ShowMessage('Lady with name '+customer.name+
>                       ' is '+IntToStr(customer.age));
>    end;
>  
>    // Close the file for the last time
>    CloseFile(myFile);
>  end;
> 
> Edited by: Christ Fill on Oct 10, 2014 8:40 AM

Please relief the tension and tell us what the showmessage displays?

-- 
Tom Brunberg
firstname.lastname@welho.com
0
Tom
10/10/2014 3:46:08 PM
{code} 
Type TEnrMess = packed record
       Mess       : String[80];
       MessSuiv   : Word;
       Hint       : Word;
   end;
{code}

Work in Delphi XE but not in Delphi 5 give EinOutError Read beyond end of file
The trick is that the file are allready generated in delphi 5 (saved) and i need to read it in Delphi XE

i thinki will need to make a converter in Delphi 5 using your packed record ...
0
Christ
10/10/2014 5:49:08 PM
Christ Fill wrote:
> {code} 
> Type TEnrMess = packed record
>        Mess       : String[80];
>        MessSuiv   : Word;
>        Hint       : Word;
>    end;
> {code}
> 
> Work in Delphi XE but not in Delphi 5 give EinOutError Read beyond end of file
> The trick is that the file are allready generated in delphi 5 (saved) and i need to read it in Delphi XE
> 
> i thinki will need to make a converter in Delphi 5 using your packed record ...

Both the writer and reader should agree on alignment of the record.  Because 
your string[80] is actually 81 bytes long the next item is going to have padding 
in before it it written if not packed.  I think you will find that the 
sizeof(TEnrMsg) is different between D5 and XE5.  The difference is the byte 
padding.  Using packed tells it not to align the record.  I think in D5 it was 
word aligned (2 bytes), later it was changed to default to quadword (8 bytes).

You can try in your XE code to change the alignment for that record to word like

{$A2}
   TEnrMess = record
      name : string[80];
      age  : Integer;
      male : Boolean;
   end;
{$A8}

The above gives the following record sizes ( sizeof(TEnrMess) )

{$A8} 92 (default for XE)
{$A4} 92
{$A2} 88 (I think this was D5's default but do not recall)
{$A1} 86 (equivalent to alignment off)


Optimally though you should always pack your records if writing them to a file 
so that changes in record alignment does not have the negative impacts you are 
seeing.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
0
Jeff
10/10/2014 6:59:40 PM
Tom Brunberg wrote:
> Jeff Overcash (TeamB) wrote:
> 
> Jeff,
> Note that Christian has shown two different structures, I don't know which is correct.
> (just noticed...)
> 

I noticed, the other one (the one I switched to in the end) is a little more 
interesting because as elements it was 81, 4, 1 and the first was 81, 2, 2 which 
was not as interesting in showing how the sizeof changes according to the alignment.

-- 
Jeff Overcash (TeamB)
       (Please do not email me directly unless  asked. Thank You)
And so I patrol in the valley of the shadow of the tricolor
I must fear evil. For I am but mortal and mortals can only die.
Asking questions, pleading answers from the nameless
faceless watchers that stalk the carpeted  corridors of Whitehall.
              (Fish)
0
Jeff
10/10/2014 7:44:35 PM
Jeff Overcash (TeamB) wrote:

> Tom Brunberg wrote:
> > Jeff Overcash (TeamB) wrote:
> > 
> > Jeff,
> > Note that Christian has shown two different structures, I don't know which is correct.
> > (just noticed...)
> > 
> 
> I noticed, the other one (the one I switched to in the end) is a little more 
> interesting because as elements it was 81, 4, 1 and the first was 81, 2, 2 which 
> was not as interesting in showing how the sizeof changes according to the alignment.

ok

-- 
Tom Brunberg
firstname.lastname@welho.com
0
Tom
10/10/2014 8:22:12 PM
Christ Fill wrote:

> {code} 
> Type TEnrMess = packed record
>        Mess       : String[80];
>        MessSuiv   : Word;
>        Hint       : Word;
>    end;
> {code}
> 
> Work in Delphi XE but not in Delphi 5 give EinOutError Read beyond
> end of file The trick is that the file are allready generated in
> delphi 5 (saved) and i need to read it in Delphi XE

Use some hex viewer to see real layout of bytes in files in both test
cases. After that you will know what to do.

--
Alex
0
Alex
10/12/2014 1:01:01 AM
Christ Fill wrote:

> 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!1ha5oOxTg7L1WJAOXutUygkjq42aTeaQT58lVYfmXI0
> 
> This sample exacly show the probleme

Not to me. I don't see an example .msg file I could try out.

Note that you may want to take care of alignment. It is probably best
to make the records packed in both versions, and do manual alignment
where that is necessary.

-- 
Rudy Velthuis        http://www.rvelthuis.de

Zymurgy's First Law Of Evolving System Dynamics: Once you open a 
can of worms, the only way to recan them is to use a larger can.
0
Rudy
10/12/2014 1:15:35 PM
Christ Fill wrote:

> {code} 
> Type TEnrMess = packed record
>        Mess       : String[80];
>        MessSuiv   : Word;
>        Hint       : Word;
>    end;
> {code}
> 
> Work in Delphi XE but not in Delphi 5 give EinOutError Read beyond
> end of file The trick is that the file are allready generated in
> delphi 5 (saved) and i need to read it in Delphi XE
> 
> i thinki will need to make a converter in Delphi 5 using your packed
> record ...

That is probably the best choice. Or you look at the file with a hex
editor and try to find out how things are aligned and you do manual
alignment to get exact the same format.

You can display the sizes of the records in both versions in a simple
test program, to see if they are the same size. Probably not.

-- 
Rudy Velthuis        http://www.rvelthuis.de

"You should never wear your best trousers when you go out to
 fight for freedom and liberty."
 -- Henrik Ibsen
0
Rudy
10/12/2014 1:17:50 PM
Hi guys

The {$A2},{$A8} do the trick, thx Jeff Overcash
you make my day ;)

Christian
0
Christ
10/14/2014 3:39:37 PM
Reply:

Similar Artilces:

Project Manager Delphi 2007 vs Delphi 5
I am in the midst of moving from Delphi 5 to Delphi 2007. I have a .BAT file that I use to do some post processing on the executable after it is built. In Delphi 5, I just added the .BAT file to the project manager. Then when I wanted to execute the .BAT file I just right clicked its entry in the project manager and selected Execute. There doesn't seem to be anyway to add the .BAT file to the project manager in Delphi 2007. How can I set up something similar to what I had in Delphi 5? I thought about using a Post Build event but I don't necessarily want to execute the .BAT fi...

Memory usage in Delphi 2007 vs. Delphi 5
Going from Delphi 5 to Delphi 2007 and finding something way unexpected. The reportedly *same code, and same data,* uses about 104 MB in Delphi 5 and about 400 MB in Delphi 2007 according to the Windows Task Manager. Now, I know that it is not the most accurate way of measuring memory usage, but it gives us an idea of the proportion of memory use in Delphi 2007. Before we go deeper, we just created 20,000 objects and added them to an object list in Delphi 5 and 2007. The result in memory use still looks like 50 MB (Delphi 5) to 178 MB (Delphi 2007). We've downloaded ...

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...

Delphi 5 to Delphi XE4
Thinking about making the conversion. Of course we have numerous components such as: TurboPower AsyncPro, TurboPower Orpheus ICS2 Synactis All-In-The-Box. You guys have any advice as to the effort and time it may possibly take. It is a large application, several hundred thousand lines. And that's what happens when using third party components, a lot of extra work. I have been burned a few times. I now minimize the use to a few well known suppliers, like TMS. I have "banned" a lot of other components. Regards, Ole > > Thinking about making the conver...

Delphi 5 to Delphi 6 and up
Dear List, Trying to add 7Zip compression support to my delphi application. I am using the ported 7Zip sdk (see their website, they have a link). I am stumped on how to rewrite a single function: function ReverseDecode(var Models: array of SmallInt; ....): ..... where the input is mostly a fixed size array of SmallInt. This code perfectly compiles and functions in Delphi 6 and up, but in Delphi 5 I get the error: There is no overloaded version of 'ReverseDecode' that can be called with these arguments And obviously, the input (fixed) isn't the same as the param de...

Delphi 5 To Delphi 2009
I upgraded to Delphi 2009 from D5. The install says I can install Delphi and/or C++. Delphi installed OK but I see nothing of C++. What am I missing or does my upgrade not include C++? Thanks It depends on what you bought. If you bought Delphi 2009 only, that's what you get. If you bought Delphi 2009 and C++ Builder 2009 you get both. My guess is you got Delphi 2009 only. The simplest way to verify is look your invoice - it should say I would think. You could also go to members.embarcadero.com, login, then click on my registered products. There will be a textual description of...

SEPA components for Delphi with Source Code (Delphi 5
Hi all, in the european union change next year the Bankingformat to the SEPA Format. All peoples and companies must change the bankingssoftware and the costumer data form acountnummers in the new IBAN and BIC numbers. See: http://www.arma-it.de/shop/artikelueber.php?wgruppeid=211&wgruppe_offen=211 Functions: - generate SEPA XML'S - Calc IBAN - BIC Database (DE,AT and CH) Questions: vertrieb@arma-it.de PS: Bankinssoftware for Develpoers (Germany only) http://www.arma-it.de/shop/artikelueber.php?wgruppeid=212&wgruppe_offen=212 El 26/10/13 21:38, A...

Upgrade from Delphi 5 and Delphi XE: Variant and SysUtils unit problems.
Hi. I am a newbie to Delhi XE. I have just taken on the task of converting my stuff from Delphi 5 [sic] to Delphi XE. The first errors I got was "Variants unit out of data or corrupted" and "symbol deprecated" in SysUtils I hope I can fix the problem by simply pointing to the "up-to-date" units. I am also wondering wether I will not have to switch to Unicode, since the errors seem to be string related (not that I know what changing to Unicode entails). Any help? Marcus > {quote:title=Marcus de Bruin wrote:}{quote} > Hi. > > I...

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...

Upgrading to Delphi 2009 from Delphi 5
I've decided it's time to upgrade to Delphi 2009 Professional from my current Delphi 5 Professional which (according to the FAQ) makes me eligible for the upgrade pricing. However, I'd just like to clarify how this process works. My concern is that my Delphi 5 is not registered on the CodeGear site and this doesn't seem to be possible as far as I can tell. When installing the trial I noticed that Delphi 2009 registers itself with your CodeGear account so does this mean that the previous version must be registered there to verify you own a Professional edition? I plan to o...

Delphi 5 to Delphi 6 conversion
Hi We are moving our product from D5 to D6. I have dealt with all the deprecated functions. However, we are getting various platform specifc warnings. These include: Symbol 'FileGetAttr' is specific to a platform Symbol 'FileSetAttr' is specific to a platform Symbol 'faReadOnly' is specific to a platform We want this conversion to be carried out correctly. We don't view the simple solution of switching off those warnings or symbols as being the correct way. What we want is the same platform independence as other functions. For example, all o...

Migration from Delphi 5 to Delphi 2005
Hi, Currently we are using Delphi 5 in that we have lot of source file now we planned to migrate from Delphi 5 to Delphi 2005. My question is - 1. Is it possible to migrate directly from Delphi 5 to Delphi 2005, my old code was developed using Delphi 5 IDE. Can we able to compile and build without any issue in Delphi 2005? 2. If we can able to do then what are the ways to migrate to Delphi 2005 IDE and also provide some link regarding this migrate? Thanks, Rizwan Rizwan Ahmed schrieb: > Hi, Currently we are using Delphi 5 in that we have lot of source > f...

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....