Solved

SizeOf() problem - Generating ESRI *.SHP Files

Posted on 2000-03-16
16
332 Views
Last Modified: 2010-08-05
Dear Experts...

I have a record structure thus:

  TMapESRIHeader = record
    FileCode: integer;
    Unused1:  integer;
    Unused2:  integer;
    Unused3:  integer;
    Unused4:  integer;
    Unused5:  integer;
    FileLength: integer;
    Version: integer;
    ShapeType: integer;
    xMin,yMin,xMax,yMax,zMin,zMax,mMin,mMax: double;
  end;

This is 9 Integers ( 9 X 4 = 36 Bytes) and 8 Doubles (8 x 8 = 64 Bytes) 100 Bytes

 

  Later in a function I declare this ...

  Header : TMapESRIHeader;


  And later, when I do this ...
      BlockWrite(fShp,Header,SizeOf(Header));
 
  I get a 104 Byte block written to my file???? I expect a 100 Byte Block.

 
Any clues on this or anyone prepared to let me have some source code for exporting SHP, SHX & DBF Files (ESRI Shape Files)

 
  Thanks, Fairport
0
Comment
Question by:Fairport
  • 7
  • 5
  • 2
  • +1
16 Comments
 
LVL 10

Expert Comment

by:Lischke
ID: 2627159
Hi Fairport,

the reason why you get 104 bytes is that Delphi aligns the record members beginning with xMin different. Try it out in the IDE:

var
  T: TMapESRIHeader;


PChar(@T.ShapeType) - PChar(@T) is 32 as expectect. That is the position of the member ShapeType in the record.

BUT PChar(@T.xMin) - PChar(@T) is not 36 as you would expect (because of the size of ShapeType being 4) but 40! This is so because the next data type is "double" so the alignment will be made to match this size.

The solution for this problem is quite simple (if you really want to have the 100 bytes). Use the keyword "packed" for your record declaration.

Ciao, Mike
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 50 total points
ID: 2627161
hi fairport,

redefine your structure to

TMapESRIHeader = packed record
    FileCode: integer;
    Unused1:  integer;
    Unused2:  integer;
    Unused3:  integer;
    Unused4:  integer;
    Unused5:  integer;
    FileLength: integer;
    Version: integer;
    ShapeType: integer;
    xMin,yMin,xMax,yMax,zMin,zMax,mMin,mMax: double;
  end;

meikl
0
 
LVL 9

Expert Comment

by:ITugay
ID: 2627162
try change declaration to

TMapESRIHeader = packed record
....


Cheers,
Igor.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2627164
hi mike :-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2627168
hi igor :-)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2627183
Hi meikl :-)
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2627188
Das war ja jetzt richtig knapp. Eine Minute länger in der IDE rumprobiert und alles wäre schon gelaufen gewesen :-)

Ciao, Mike
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2627258
? mike, wieso ?
du weißt doch das ich nur kommentiere.
aber knapp war's scho ;-))
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 9

Expert Comment

by:ITugay
ID: 2627292
Wirklich eine Minute! Ich werde geerschwert,  zu verstehen. Ich sehe einige Buchstaben nicht. Aber es ist hallo egal!

By,
Igor.
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2627367
Hey Igor, seems you understand german :-) Well, german Delphi programmers are a quite large fraction here at E-E...

Meikl, what I meant was that I wouldn't have been the first one here a minute later (and I have spent already a few minutes in the IDE to make sure my answer is correct).

Ciao, Mike
0
 

Author Comment

by:Fairport
ID: 2631061
Thanks...
Vey Clear and to the point.
We had actually found the problem & reason by the next day ourselves... but the "PACKED" record was not something I knew about.

0
 
LVL 10

Expert Comment

by:Lischke
ID: 2631105



               WHY



have you then rejected my anser??? I was not only the first one with the correct answer I provided you with additional information why the alignment is so and I spent time on YOUR problem, not mine.


Ich bin so sauer, ich kann es hier gar nicht ausdrücken ohne unhöflich zu werden.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 2631272
? just wondering also,
because mike has pointed
you also to use the packed record definition

but anyway thanks for accepting my comment as answer ;-)

mike, nicht sauer sein,
(ich weiß, ich hab gut reden,
nachdem ich der nutznießer bin.
ich denke, ich würde
auch ganz schön sauer sein)
hast aber mein vollstes verständnis und
meine hochachtung vor deiner inneren disziplin.

bled glofn

meikl
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2631760
I'm already beyond it..., seufz :-)

Ciao, Mike
0
 

Author Comment

by:Fairport
ID: 2632410
Lischke...
V sorry!!

I tried to work out how to reverse my rejection yesterday...
Sincere apologies. If I could have found a way to reverse the rejection I would have given you the points.

This was my first time in EE... When I displayed the answer on my Browser... all I saw were your remarks to someone regarding being German or something... and a set of radio buttons that asked if I accepted or not... so I rejected... then soon afterwards I saw that your answer was ok but could not find a way to sort out the problem I had caused!!!

Again sincere aplogies. I won't make that mistake again.

If I can buy you a beer one day... send you a cheque in the mail...or??

Thanks for your answer -
0
 
LVL 10

Expert Comment

by:Lischke
ID: 2634147
Ok, accepted. Although I prefer wine, a beer would not be bad :-)

Next time you 'll make it better, I'm sure.

Ciao, Mike
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now