 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Dave Guest
|
Posted: Mon Dec 01, 2003 3:54 pm Post subject: Nested Array of Records.. Help |
|
|
Hi,
I want to implement a nested array of records in Delphi, look at my
code below...
type FileData = packed record
file_path: String[31];
File_Name: String[31];
extension: String[3];
filesize: LongWord;
end;
type LoadFiles = packed record
num_entries: LongWord;
InfoData: Array[0..num_entries] of FileData;
end;
The compiler complains about num_entries being an undeclared
identifier.
As you can see, what I want to achieve is to creae a dynamic array of
nested records, any suggestions??
Thanks.
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Mon Dec 01, 2003 5:45 pm Post subject: Re: Nested Array of Records.. Help |
|
|
"Dave" <engdmorr (AT) yahoo (DOT) com> wrote
[...]
| Quote: | type LoadFiles = packed record
num_entries: LongWord;
InfoData: Array[0..num_entries] of FileData;
end;
The compiler complains about num_entries being an undeclared
identifier.
As you can see, what I want to achieve is to creae a dynamic array of
nested records, any suggestions??
|
You can do it dynamically, but not statically. You can write the
number of entries to the file, and then as many records, and on
reading them you can read the number first, adjust a dynamic array
of TFileData[0] records and read them in as a block. But this is
not a valid record declaration.
Groetjes,
Maarten Wiltink
[0] Don't forget the initial 'T'. It's a 'T'ype, after all.
(Just making things easy on the humans.)
|
|
| Back to top |
|
 |
AlanGLLoyd Guest
|
Posted: Mon Dec 01, 2003 6:28 pm Post subject: Re: Nested Array of Records.. Help |
|
|
In article <274ea43b.0312010754.7cada316 (AT) posting (DOT) google.com>,
[email]engdmorr (AT) yahoo (DOT) com[/email] (Dave) writes:
| Quote: | I want to implement a nested array of records in Delphi, look at my
code below...
type FileData = packed record
file_path: String[31];
File_Name: String[31];
extension: String[3];
filesize: LongWord;
end;
type LoadFiles = packed record
num_entries: LongWord;
InfoData: Array[0..num_entries] of FileData;
end;
The compiler complains about num_entries being an undeclared
identifier.
|
Records must essentially be declared as a fixed length of memory. You would be
able to do what you want by declaring ...
type LoadFiles = packed record
num_entries: LongWord;
InfoData: Array[0..0] of FileData;
end;
You will know how much memory to allocate to a particular record, and how to
write and read it.
PtrMyLoadFiles := AllocMem(SizeOf(TLoadFiles + Num_Entries * SizeOf(FileData));
But you would be far better off using an object class of a descendant of TList
or something similar.
BTW it is better to stay with the Delphi convention of a "T" Prefix for a type
and a "P" prefix for a pointer to a defined type. Personally I would also use
"Ptr" as a prefix for a pointer variable.
Alan Lloyd
[email]alanglloyd (AT) aol (DOT) com[/email]
|
|
| Back to top |
|
 |
Tom de Neef Guest
|
Posted: Mon Dec 01, 2003 8:25 pm Post subject: Re: Nested Array of Records.. Help |
|
|
"Dave" <engdmorr (AT) yahoo (DOT) com> wrote some mesage
| Quote: |
type TFileData = packed record |
file_path: String[31];
File_Name: String[31];
extension: String[3];
filesize: LongWord;
end;
type TLoadFiles = class
num_entries: LongWord;
InfoData: Array of TFileData;
procedure ReadFromFile(filename : string);
procedure WriteToFile(filename : string);
end;
procedure TLoadFiles.ReadFromFile(filename : string);
var
stringlist : Tstringlist;
k : integer;
begin
stringlist:=Tstringlist.create;
stringlist.LoadFromFile(filename);
num_entries:=stringlist.count;
setLength(InfoData,num_entries);
for k:=0 to num_entries-1 do
begin InfoData[k].file_path:=copy(stringlist[k],1,31);
InfoData[k].file_name:=copy(stringlist[k],32,31);
InfoData[k].extension:=copy(stringlist[k],63,3);
try InfoData[k].filesize:=StrToInt(copy(stringlist[k],66,maxint))
except reporterror end
end;
stringlist.free
end;
procedure TLoadFiles.WriteToFile(filename : string);
var
stringlist : Tstringlist;
k : integer;
begin
stringlist:=Tstringlist.create;
for k:=0 to num_entries-1 do with InfoData[k] do
stringlist.add(file_path+file_name+extension+IntToSTr(filesize));
stringlist.saveToFile(filename);
stringlist.free
end;
That is, if you do want to be able to read your stored data on file and if
you do not care much about performance.
Tom
|
|
| Back to top |
|
 |
Dave Guest
|
Posted: Tue Dec 02, 2003 11:48 am Post subject: Re: Nested Array of Records.. Help |
|
|
Thanks for the replys, will investigate TList.
Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
Note to Borland, Microsoft and all you other compiler makers, give me
a break damn it!!
|
|
| Back to top |
|
 |
AlanGLLoyd Guest
|
Posted: Tue Dec 02, 2003 3:53 pm Post subject: Re: Nested Array of Records.. Help |
|
|
In article <274ea43b.0312020348.4e5b2516 (AT) posting (DOT) google.com>,
[email]engdmorr (AT) yahoo (DOT) com[/email] (Dave) writes:
| Quote: | Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!!
|
Delphi _is_ easy, what you call "messing around" is just learning something
about what you are doing. If you're not prepared to do that, then just read a
book. OTOH why should one have to understand all those squiggles, just make
sounds of some sort <g>.
Alan Lloyd
[email]alanglloyd (AT) aol (DOT) com[/email]
|
|
| Back to top |
|
 |
Bruce Roberts Guest
|
Posted: Tue Dec 02, 2003 5:30 pm Post subject: Re: Nested Array of Records.. Help |
|
|
"Dave" <engdmorr (AT) yahoo (DOT) com> wrote
| Quote: | Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
|
Lots of programming languages have been designed. Unfortunately they all
have one thing in common, they don't read a programmer's mind. Alas,
programmers, like children around the world, have to invest some effort into
learning syntax, semantics, and vocabulary.
|
|
| Back to top |
|
 |
J French Guest
|
Posted: Tue Dec 02, 2003 5:31 pm Post subject: Re: Nested Array of Records.. Help |
|
|
On 2 Dec 2003 03:48:49 -0800, [email]engdmorr (AT) yahoo (DOT) com[/email] (Dave) wrote:
| Quote: | Thanks for the replys, will investigate TList.
Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
Note to Borland, Microsoft and all you other compiler makers, give me
a break damn it!!
|
If you are trying to look at historical data then look at this
Type TRec = Packed Record
S : String[30];
End;
procedure TForm1.Button1Click(Sender: TObject);
Var
R :TRec;
begin
ShowMessage( IntToStr( SizeOf(R) ) );
R.S := 'Hullo';
ShowMessage( IntToStr( Ord( R.S[0] ) ) );
end;
ShortStrings are unlikely to fit your requirements.
- there is an extra byte stored holding the 'used length'
I reckon that Tom de Neef was trying to demonstrate the advantages of
human readable storage
Although packed records have their place(s)
|
|
| Back to top |
|
 |
Terry Russell Guest
|
Posted: Tue Dec 02, 2003 9:27 pm Post subject: Re: Nested Array of Records.. Help |
|
|
"Dave" <engdmorr (AT) yahoo (DOT) com> wrote
| Quote: | Thanks for the replys, will investigate TList.
Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
|
It is easy, like building a house, all you need is a lot of bricks and some
patience.
| Quote: |
Note to Borland, Microsoft and all you other compiler makers, give me
a break damn it!!
|
for ....
begin
...
goto damnit;
...
end;
....
damnit: ...
|
|
| Back to top |
|
 |
David Reeve Guest
|
Posted: Wed Dec 03, 2003 2:08 am Post subject: Re: Nested Array of Records.. Help |
|
|
"Dave" <engdmorr (AT) yahoo (DOT) com> wrote
| Quote: | Thanks for the replys, will investigate TList.
Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
|
It's not just confined to programming languages. I've been to foreign lands
where the local inhabitants speak incomprehsible gibberish. Like you say,
its appauling (sic), a joke, just plain nasty :-)
Dave
|
|
| Back to top |
|
 |
Henry Bartlett Guest
|
Posted: Wed Dec 03, 2003 2:38 am Post subject: Re: Nested Array of Records.. Help |
|
|
Dave
Have you ever wondered why it takes a child around 12 months to begin
to talk and then another few years before they are fluent in their
native language.
There are at least 2 reasons
It takes time for their brains to develop to the stage where they are
able to process language, more time to learn the meanings of words
(vocabulary) and still more time to learn how the language works
(syntax). Brain development and learning cannot be separated as
learning develops the brain.
Learning a programming language is similar. You have to invest the
time and effort but once you have become proficient in one, others
come more easily.
| Quote: | Is anyone actually going to invent a programming language where
stuff like this is easy
|
You mention Java, C++ and Delphi as difficult-to-handle languages.
LOGO, BASIC and Pascal were developed as "baby languages", easy to
learn, but not very useful in their "baby" form. I have listed them in
order of their difficulty, which just happens to be in the same order
as their usefulness.
Have you looked at PERL or QUOLLX?
If you don't know them then try Googling for them.
Google should find plenty of references to PERL and it's _possible_
that you may find it easy, but I doubt it, if your mind is anything
like mine.
As for QUOLLX, Google may find nothing about it since it's a name I
just made up (an "undeclared identifier").
Does that tell you anything? 8-)
--
Henry Bartlett
|
|
| Back to top |
|
 |
Nicolai Hansen Guest
|
Posted: Wed Dec 03, 2003 7:47 am Post subject: Re: Nested Array of Records.. Help |
|
|
[email]engdmorr (AT) yahoo (DOT) com[/email] (Dave) wrote in message news:<274ea43b.0312020348.4e5b2516 (AT) posting (DOT) google.com>...
| Quote: | Thanks for the replys, will investigate TList.
Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
Note to Borland, Microsoft and all you other compiler makers, give me
a break damn it!!
|
What you want to do is easily doable in C. It even got a name, just
can't remember it :)
It is also easily doable in Delphi if you use "object" instead of
"record".
type TLoadFiles = object
num_entries: LongWord;
InfoData: Array of FileData;
constructor Create(number_entries: Longword);
destructor Destroy();
end;
constructor TLoadFile.Create(number_entries: Longword);
begin
num_entries:=number_entries;
SetLength(InfoData, number_entries);
end;
destructor TLoadFile.Destroy();
begin
InfoData:=nil;
end;
/Nic
|
|
| Back to top |
|
 |
Maarten Wiltink Guest
|
Posted: Wed Dec 03, 2003 2:06 pm Post subject: Re: Nested Array of Records.. Help |
|
|
"Henry Bartlett" <hambar (AT) Spamlock (DOT) microtech.com.au> wrote
[...]
| Quote: | Have you looked at PERL or QUOLLX?
[...]
Google should find plenty of references to PERL and it's _possible_
that you may find it easy, but I doubt it, if your mind is anything
like mine.
|
You need a seriously warped mind to deal with PERL. No need to worry
about that, though. If your mind isn't warped just right, it will be
afterwards.
| Quote: | As for QUOLLX, Google may find nothing about it since it's a name I
just made up (an "undeclared identifier").
|
Did you mean: http://home.mira.net/~areadman/quoll.htm
This language doesn't exist, but should.
Groetjes,
Maarten Wiltink
|
|
| Back to top |
|
 |
Henry Bartlett Guest
|
Posted: Thu Dec 04, 2003 8:50 pm Post subject: Re: Nested Array of Records.. Help |
|
|
Bjørge Sæther <bjorge (AT) hahaha_itte (DOT) no> wrote
| Quote: | "Henry Bartlett" <hambar (AT) Spamlock (DOT) microtech.com.au> skrev i melding
What I don't understand here and now, is what this has to do with
the
topic....
|
Not a lot, 8-)
but I thought that it was relevant to Dave's post, in this thread, of
2 Dec 2003 03:48:49 -0800, which I was replying to, and in which he
wrote
| Quote: | Is anyone actually going to invent a programming language where
stuff
like this is easy, rather than all this messing around we have to do
all the time!! Java is appauling, C++ is a joke and Delphi is just
plain nasty!!
Note to Borland, Microsoft and all you other compiler makers, give
me
a break damn it!!
|
--
Henry Bartlett
|
|
| Back to top |
|
 |
Marco van de Voort Guest
|
Posted: Sun Dec 07, 2003 3:18 pm Post subject: Re: Nested Array of Records.. Help |
|
|
On 2003-12-02, Dave <engdmorr (AT) yahoo (DOT) com> wrote:
| Quote: | Thanks for the replys, will investigate TList.
Is anyone actually going to invent a programming language where stuff
like this is easy, rather than all this messing around we have to do
all the time!!
|
The problem is that easy is either dog slow (because of all the checking,
and runtime work going on), and often even dangerous when the code pieces
go beyond simple examples in a NG.
This is one of them.
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|